Conditional Redirects
Hi, first time exploring the stack and NextAuth. I've extended the default NextAuth User model to include a reference to another model (Team), and I want the following behavior:
1. User logs in/is logged in
2. Check which team the User belongs to (column on the table User).
3. redirects to /<team-id>
Whats the stacks opinion on how this should be done? I see some possibility of using getServerSideProps but I recall Theo saying T3 tries to avoid server side rendering? Am i supposed to be messing with the session() and redirect() callbacks in [...nextauth].ts or something entirely else?
13 Replies
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
gotcha. Where should that query actually take place? i.e. where can I hook into the flow to do a db query before the redirect actually occurs?
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
hmm so Im using the nextAuth signIn() hook
so the only api/auth route is the [..nextauth].ts stuff
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
looks like there are redirect() and session() callbacks in the NextAuth options (session() is defined by default with create-t3-app). Would I end up doing the query in there or am i totally misunderstanding ur point
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
hmm this is weird.seems like there should be an obvious thing to do here with next auth right?
like for instance in the session() callback, we attach the user id to session.user.id. should there be a db check and also attach my other data at that point maybe?
and then, client side redirect with that sessionData
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
yeahh those ones
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
ah gotcha. Will try that out
really appreciate it!
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View