T3 NextAuth - Email Provider WITH Username

I've gone through a few T3 tutorials and I'm creating my own application now. Does anyone know the correct way to add a username to the initial user-signup via the NextAuth email provider? Yes, I could have the user specify their username AFTER they click the link in their inbox, but it would be nice if they specified it when they type in their email during signup. I could create a route for a username mutation but the user technically doesn't exist in the database until AFTER they click the link in their inbox. Could someone describe how this could be done? Any code example resource would be a bonus.
8 Replies
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Bennett
Bennett•3y ago
How would putting it in the callback URL help? Where would you have access to it? Isn't NextAuth doing this internally via the catch-all API route?
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Bennett
Bennett•3y ago
Ah, understood, thanks. In my case, I want to have a custom, unique username in my application and don't use the name coming from the providers (like Google). As one has no influence in creating a user via NextAuth, I need to set a username AFTER the initial sign in. What really annoying about this is that my username now needs to be optional in the Prisma schema, as it is not a filled field when a user is created.
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Bennett
Bennett•3y ago
I don't feel comfortable keeping this in sync honestly, would rather "extend" the Prisma adapter of NextAuth.
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Bennett
Bennett•3y ago
I also think you can't... Was just talking about my wishes 😅 Maybe for now I will initialize the username with a CUID via Prisma and add a boolean flag to the schema (something like isInitialized), which then asks the user to set his username after sign in.

Did you find this page helpful?