Inspect authentication flow
Local development
Auth.js · Pipe
Auth.js’s debug option enables detailed console diagnostics for authentication and database activity. Prefer enabling it during development and protect or sanitize logs because they can contain sensitive information.
Set the Auth.js debug option to true to emit detailed authentication and database-operation messages through the console. Use it while diagnosing development issues, or combine it with a custom logger when logs must be routed or formatted differently.
debug: boolean| Name | Type | Description |
|---|---|---|
debug | boolean | Boolean flag that enables debug messages for authentication and database operations. |
import NextAuth from "next-auth"
export const { handlers, auth } = NextAuth({
debug: process.env.NODE_ENV !== "production",
})Enable diagnostic logging during development while avoiding it in production.
Local development
Incident diagnosis
Centralized observability
Set debug: true in the object passed to NextAuth. Auth.js then uses console methods to report authentication details, including requests, responses, errors, and database activity.
Follow-up: How should production configuration differ? Use a condition such as process.env.NODE_ENV !== "production" so verbose diagnostics are disabled in production.
Provide a logger object with error, warn, and debug methods in the Auth.js configuration. Those methods receive a code and additional message values, allowing output to be sent to another service or reformatted.
Follow-up: What happens if both options are configured? The custom logger wins and the debug option is ignored.
Debug output can include authentication and database requests and responses, as well as errors. Because those details may expose sensitive information, production logs must be handled carefully.
Follow-up: What is a safer default? Enable debugging only outside production and sanitize any diagnostic data that is retained.
loggerAuthConfigWarningCodedebug-enabled