Next.js Discord

Discord Forum

Next-Auth add a custom "new-user" page and handle the form

Unanswered
Brewer's Blackbird posted this in #help-forum
Open in Discord
Brewer's BlackbirdOP
I want to force user to provide a username in "new-user" page and if user leaves the page, provide a default value "user[userId]".
Is there a better way to do it? For example, events, i've tried to do it using events, but it didn't work.

Here is the example of how i've tried to do it using event

32 Replies

Brewer's BlackbirdOP
code block is more preferable
use the session() callback to handle new users
events are meant to be side effects and not for db calls
although
@alfon code block is more preferable
Brewer's BlackbirdOP
ok, i'll take the advice
i thought you already use prisma adapter
you don't need to update again unless you want to change it even after the update?
Brewer's BlackbirdOP
I use t3 stack. It provides a boilerplate for prisma where user have fields like name, email. I added another unique field "username". When user signs in via github or discord i want them to be redirected to /auth/new-user page where they should provide a username or else it will be set to default value "user[id"]
Or is there a better way to implement this?
ahh i see
i have no clue on how to add custom new user page natively in nextauth
but i have some idea
such as returning the session with isInitialized flag put in your session object
if its not initialized, then redirect to new user
if its initialized then continue as usual
so after finishing the new-user page you can useSession().update() to update session to mark isInitialized to true
Brewer's BlackbirdOP
thanks, i'll try that
@alfon such as returning the session with `isInitialized` flag put in your session object
Brewer's BlackbirdOP
I should extend the session interface and add isInitialized to prisma schema, right?
oh yeah
that too
Brewer's BlackbirdOP
So then i should make the username field optional, because user is created after they signed in via provider and username will be set later, right?
whaaa
your username should be in the register page, not the new-user page
i thought ure talking about the introductory page after a new user had signed in
Brewer's BlackbirdOP
oops
ok my bad
Brewer's BlackbirdOP
is there a github repo with custom sign up page for providers? I couldn't find one
@alfon your username should be in the register page, not the new-user page
Brewer's BlackbirdOP
Do you know how to implement it? After they signed in via provider, make them provide additional data (username)?