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 can't get the redirect callback to give the token or session to be able to redirect a user based on role. this is the redirect callback I have:
async redirect({
url,
baseUrl,
token,
session,}: {
url: string;
baseUrl: string;token?: JWT;session?: Session;}){console.log("Redirect callback - token:",token);console.log("Redirect callback - session:",session);// If the URL is not part of the application, redirect to homeif(!url.startsWith(baseUrl)){returnbaseUrl;}console.log("Redirect Role:",token?.role);console.log("Redirect Session:",session);// Check if user is super admin from the tokenif(token?.role==="super_admin"){console.log("Super Admin detected, redirecting to dashboard");return`${baseUrl}/dashboard`;}// Default redirect to homereturnbaseUrl;},},
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
Uh oh!
There was an error while loading. Please reload this page.
-
I can't get the redirect callback to give the token or session to be able to redirect a user based on role. this is the redirect callback I have:
Output is :
Redirect callback - token: undefined
Redirect callback - session: undefined
Redirect Role: undefined
Redirect Session: undefined
how does one redirect a user based on role.
using
"next": "15.1.6",
"next-auth": "^5.0.0-beta.25",
"react": "^19.0.0",
Beta Was this translation helpful? Give feedback.
All reactions