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 using NextAuth with the PrismaAdapter and Google/Email providers to manage authentication in my Next.js app. My goal is to implement the following logic for user sign-in:
First-time sign-in:
If the user signs in for the first time, their account should be created in the database with an isApproved field set to false.
They should then be redirected to an error page (/auth/error) informing them their account is pending approval.
Subsequent sign-ins (when isApproved = false):
If the user tries to sign in again while their account is still unapproved (isApproved = false), they should again be redirected to the error page (/auth/error).
Subsequent sign-ins (when isApproved = true):
If the user is approved (isApproved = true), they should be successfully logged in and redirected to the /dashboard page as expected.
I’ve attempted to implement this in the signIn callback, but I’m encountering issues where:
On first-time sign-in, since the user isn’t already in the database, the logic checks isApproved and fails.
I’m unsure of the best way to conditionally create the user on first-time sign-in while maintaining this approval flow. Because when I update my code to put the user in the database first, it redirects the user to my /dashboard even if the isApproved is false.
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
-
Hello,
I’m using NextAuth with the PrismaAdapter and Google/Email providers to manage authentication in my Next.js app. My goal is to implement the following logic for user sign-in:
First-time sign-in:
Subsequent sign-ins (when isApproved = false):
Subsequent sign-ins (when isApproved = true):
I’ve attempted to implement this in the signIn callback, but I’m encountering issues where:
Here’s my current [...nextauth].ts file:
Thank you for your help 💯
Beta Was this translation helpful? Give feedback.
All reactions