Email requires adapter
, which makes session strategy default to database
. Middleware then doesn't work.
#4891
Labels
documentation
Relates to documentation
triage
Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
What is the improvement or update you wish to see?
Hello, I coudln't figure out for the life of me why the middleware kept sending me to the sign in page. What I ended up doing was:
Email
provideradapter
andprovider
in my[...nextauth.js]
filemiddleware.ts
file in root to protect everything. Awesome!session
configuration option which let me know that ifadapter
is specified it defaults todatabase
.Once I changed the session strategy back to
jwt
, everything worked great againI would like to suggest a few fixes:
Email Provider
docs that because the email provider requires the use of anadapter
in the configuration, then thesession: { strategy: '...' }
will automatically be switched todatabase
and you need to explicitly specifyjwt
in the session strategy if you are also wanting to make use ofmiddleware.ts
middleware.ts
is being used and the session strategy isdatabase
then middleware will not work as expectedadapter
is configured but there is no explicit session strategy specified, and the user has amiddleware.ts
file in the root, then the console should send a warning/info noticed (maybe supressable) stating that the default session strategy has been set todatabase
I know it's a new feature but the combination of factors caused this to go undetected for quite a while and it was pure luck I stumbled upon the correct combination of docs.
Is there any context that might help us understand?
I just started using next-auth.js within the last few days.
Here are the relevant docs:
https://next-auth.js.org/providers/email
Lets us know that we need to set up an adapter, but doesn't note how this impacts middleware usage.
https://next-auth.js.org/tutorials/securing-pages-and-api-routes
Lets us know how to use the new middleware feature, noting that
jwt
must be used.https://next-auth.js.org/configuration/options#session
Lets us know that session strategy defaults to
database
if you use an adapter and don't set it explicitly, but doesn't note that this may produce unexpected results if you then go on to use middleware.Does the docs page already exist? Please link to it.
No response
The text was updated successfully, but these errors were encountered: