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
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
alexjyoung
alexjyoung2y ago
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
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
alexjyoung
alexjyoung2y ago
hmm so Im using the nextAuth signIn() hook so the only api/auth route is the [..nextauth].ts stuff
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
alexjyoung
alexjyoung2y ago
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
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
alexjyoung
alexjyoung2y ago
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
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
alexjyoung
alexjyoung2y ago
yeahh those ones
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
alexjyoung
alexjyoung2y ago
ah gotcha. Will try that out really appreciate it!
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server