偵錯
偵錯 Auth.js 首先要啟用您主要 Auth.js 設定中的 debug
選項。
./auth.ts
import NextAuth from "next-auth"
export const { handlers, auth } = NextAuth({
debug: true,
})
這將使用 console
方法來記錄有關身份驗證過程的許多詳細資訊,包括請求、響應、錯誤以及資料庫請求和響應。
記錄
您可以透過提供自己的記錄器來自訂記錄輸出。如果您想將日誌發送到日誌服務,或者如果您想自訂日誌的格式,這會很有用。
./auth.ts
import log from "logging-service"
export const { handlers, auth } = NextAuth({
logger: {
error(code, ...message) {
log.error(code, message)
},
warn(code, ...message) {
log.warn(code, message)
},
debug(code, ...message) {
log.debug(code, message)
},
},
})
⚠️
在生產環境中啟用 debug
選項可能會導致敏感資訊儲存在您的日誌中。請務必清理任何敏感資訊。
當設定 logger
選項時,debug
選項會被忽略