You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using next-auth v5 for authentication and my application supports two types of sessions: guest and authenticated. To manage that, I am using two separate credentials providers. For guest sessions I need to programmatically log in users directly in the middleware.
Current approach
Redirect to a separate guest route endpoint in the middleware.
Trigger signIn server action from next-auth in that guest route endpoint.
Problem
This approach introduces an unnecessary redirect which causes white screen blinking. Ideally, I want to log in the user directly in the middleware. However, server actions cannot be called directly in middleware.
Question
How can I programmatically log in a user directly in the middleware without a redirect, given the constraint that server actions cannot be used in middleware?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Background
I am using next-auth v5 for authentication and my application supports two types of sessions: guest and authenticated. To manage that, I am using two separate credentials providers. For guest sessions I need to programmatically log in users directly in the middleware.
Current approach
signIn
server action from next-auth in that guest route endpoint.Problem
This approach introduces an unnecessary redirect which causes white screen blinking. Ideally, I want to log in the user directly in the middleware. However, server actions cannot be called directly in middleware.
Question
How can I programmatically log in a user directly in the middleware without a redirect, given the constraint that server actions cannot be used in middleware?
Beta Was this translation helpful? Give feedback.
All reactions