Role is undefined when using NextAuth

Hello I am trying to create role based authorization and attempting to access the user's role from useSession in Next and from protected routes in trpc.

I have added a UserRole to the user model in the prisma schema using an enum, and defaulted it to USER. Also in the server/auth ive added the role to Session and user interfaces and to the session callback.

I have seen other people using a signIn or jwt callback and have no clue what they do or mean.

When I do use access the role in useSession in NextJS or throuhg ctx in protected routes, the role is undefined. Can anybody give me some insight into how all of this works and the flow of data for the session.

Thankyou
image.png
image.png
image.png
image.png
image.png
Was this page helpful?