NextAuth v5 silently switches session storage based on adapter configuration
NextAuth (Auth.js) v5 determines session strategy implicitly: without an adapter it defaults to JWT, but adding an adapter like DrizzleAdapter silently shifts session storage to the database. A key complication arises with the Credentials provider, which cannot create database sessions, causing a silent authentication failure when an adapter is present without an explicit JWT override. Developers must set session: { strategy: 'jwt' } globally when using Credentials, since NextAuth does not support mixing strategies per provider. One practical workaround is to enable the Credentials provider only in non-production environments, switching to JWT strategy exclusively for testing while keeping OAuth on database sessions in production. Understanding these two implicit rules resolves common NextAuth puzzles such as undefined token values in callbacks and logins that appear to succeed but produce no active session.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in