Insert Role before authenticating in Next Auth

The create-t3-app provides a small explanation about how to modify the User model in Prisma's schema.prisma file. It mentions that we need to add a default role. But while using an auth provider, for example google, I want to know how to let next-auth and Prisma know the role of the user before the user is authenticated and their details are entered into the database? It seems like after the authentication, the user is automatically added to the database and the callback session of next auth is executed only later. I have 2 roles in my app (a seller and a buyer). Both have different pages but use the same signin function to authenticate. How do I tell the signin function to add a particular role instead of the default one? Thanks
6 Replies
Neto
Neto3y ago
the user is automatically added to the database and the callback session of next auth is executed only later. it is lol prisma only store the result on the database you can set a nullable role, sign in the user, if the use does not have a role, ask him to select one of the two update
amur_sri
amur_sriOP3y ago
Hmm, I see. But there is no way to do this while the user is authenticating. Only after the user's details have been entered into the database
Neto
Neto3y ago
yes its the default behaviour of the prisma adapter
amur_sri
amur_sriOP3y ago
Alright. And can it be done programmatically? Like instead of displaying a new page where they choose their role, can I check which page they came from and update the User in the database?
Neto
Neto3y ago
its an option but i think just a modal with "are you a buyer or a seller?" its a more simple approach if the user doesnt select an option he cant perform actions
amur_sri
amur_sriOP3y ago
Yeah, makes sense. Thanks
Want results from more Discord servers?
Add your server