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'm attempting to retrieve the user session immediately after calling signIn with redirect: false inside a Next.js server action. The goal is to dynamically calculate the redirect URL based on the user's role. However, when I call auth() right after signIn, it returns null.
Expected Behavior
After calling signIn with redirect: false, I should be able to retrieve the user session immediately using auth() to determine the user's role and calculate the redirect URL.
Actual Behavior
When calling auth() immediately after signIn, it returns null, making it impossible to calculate the redirect URL based on user data.
Steps to Reproduce
Call signIn with redirect: false in a Next.js server action.
Call auth() right after signIn to retrieve the session.
Observe that auth() returns null.
Current Workaround
Use a temporary route for signIn.
Employ middleware to redirect based on the user's role.
Problems with this workaround:
The URL in the browser's address bar does not update correctly.
The approach feels hacky and less maintainable.
Question
What is the best way to dynamically calculate the redirect URL based on user data after signIn without encountering the above issues?
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
-
Description
I'm attempting to retrieve the user session immediately after calling
signIn
withredirect: false
inside a Next.js server action. The goal is to dynamically calculate the redirect URL based on the user's role. However, when I callauth()
right aftersignIn
, it returnsnull
.Expected Behavior
After calling
signIn
withredirect: false
, I should be able to retrieve the user session immediately usingauth()
to determine the user's role and calculate the redirect URL.Actual Behavior
When calling
auth()
immediately aftersignIn
, it returnsnull
, making it impossible to calculate the redirect URL based on user data.Steps to Reproduce
signIn
withredirect: false
in a Next.js server action.auth()
right aftersignIn
to retrieve the session.auth()
returnsnull
.Current Workaround
signIn
.Problems with this workaround:
Question
What is the best way to dynamically calculate the redirect URL based on user data after
signIn
without encountering the above issues?Environment
Beta Was this translation helpful? Give feedback.
All reactions