I have what seems to be a conceptual doubt about where and how to implement user role logic in a next-auth app and which approach is the most conventional.
Namely when using something like this
providers: [
Auth0Provider({
clientId: env.AUTH0_CLIENT_ID,
clientSecret: env.AUTH0_CLIENT_SECRET,
issuer: env.AUTH0_ISSUER,
profile(profile) {
return {
id: profile.sub,
name: profile.name,
email: profile.email,
image: profile.picture,
role: //HERE I CAN SET
} as User;
},
}),
],
This correctly sets up the role when hardcoded, the Prisma adapter is working too and I can get it all the way to the frontend with the session callback
callbacks: {
session: ({ session, user }) => ({
...session,
user: {
...session.user,
id: user.id,
role: user.role,
},
}),
},
What I don’t understand is where to get this logic from, how can I send it to next-auth.
The only thing I can come up with is something like setting a cookie with the role, let’s say I have two buttons one for customer signup and another for partner signup, before redirecting to /api/auth/signin
I could set a cookie, but this is kind of ugly to do it next-js app router from the client side, and I seem to be missing something obvious here.