#Implementing onboarding using next-auth

15 messages · Page 1 of 1 (latest)

rough fjordBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

vivid panther
#

You can setup a page where users will be sent after they first sign up in your NextAuth config. It's called newUser. Reference

#

Define a newUser page in your NextAuth config. Check the reference I linked

#

NextAuth will automatically check if they already signed up before or not and if not, redirect them to the page you defined

#

Nope, you don't

#

Not much has changed for use in the app router. I'm using app router as well and most things still apply

#

Authentication with NextAuth is actually pretty easy once you understood how it works

#

You are adding custom properties. By default, NextAuth will store 3 things in your session/token: email, name and image which are all coming from the OAuth provider the user used.
If you want to add custom properties from your database, like username, your own image, access roles (admin, moderator etc.), you add them inside the callback functions

#

token is the token NextAuth created on sign up and session is the user session which you can get on the client side using the useSession hook

#

Because on the client side you can not decrypt the token but you can use the session so everything you want to use on the client side has to be added to the session

#

Kind of

#

The token NextAuth creates only includes name, email and image. Everything else is added in the jwt callback from your database. You can then add those values into the session as well using the session callback

#

Yes, that will be your JWT payload

#

And that will be what your token variable will include in your session callback

#

I actually don't know for custom redirects. I suggest letting NextAuth handle the redirect on sign in