Theo's Typesafe CultTTC
Theo's Typesafe Cult4y ago
3 replies
Less

Prisma nexth-auth role based access control model

Hi, just getting started with the t3-stack and prisma. I'm a little confused on why the Account model is required for next-auth.

Also, I'm not sure how to add a role that would give me type definitions when using the session.

Yes, I did looked it up and I followed the tutorial from next-auth, but that doesn't give me the type definitions on the user when setting up the session. https://next-auth.js.org/tutorials/role-based-login-strategy

Also, I've already changed the next-auth.d.ts file to include the role.
declare module "next-auth" {
  /**
   * Returned by `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context
   */
  interface Session {
    user?: {
      id: string;
      role: string;
    } & DefaultSession["user"];
  }
}

Edit-1: Add next-auth types info;
To add role based authentication to your application, you must do three things.
Was this page helpful?