NextAuth and role based access control
Can someone explain to me how to modify the the auth.ts file in the server folder when you set up a boilerplate t3 app with next auth in order to enable role based access control? I have been using a profile() callback (https://authjs.dev/guides/basics/role-based-access-control) with a GitHubProvider but I get an error with my prisma schema. I added this in my User model
role String @default("user")
but no luck. Would really appreciate some insight on how to do this.Role-based access control | Auth.js
There are two ways to add role-based access control (RBAC) to your application, based on the session strategy you choose. Let's see an example for each of these.
2 Replies
I think I figured this out. The User interface needs to be in the next-auth module that's declared. I also was spreading in the profile object from the GitHubProvider which I think was not compatible with the prisma User Schema. Instead, I just grabbed the values I wanted.
Here is my full repo if anyone else is struggling to figure this out: https://github.com/DocMDC/RoleBasedAccessControlT3NextAuth
GitHub
GitHub - DocMDC/RoleBasedAccessControlT3NextAuth
Contribute to DocMDC/RoleBasedAccessControlT3NextAuth development by creating an account on GitHub.