Next.js Discord

Discord Forum

Getting User Role in NextAuth

Unanswered
Asiatic Lion posted this in #help-forum
Open in Discord
Asiatic LionOP
what is the proper way to get the user role in nextAuth?
i have a user schema and I can only fetch the email, name

i want to also fetch the id and the role
async session({ token, session }) {
      if (token) {
        session.user.id = token.id as string;
        session.user.name = token.name;
        session.user.email = token.email as string;
        session.user.role = token.role as Role;
      }
      return session;
    },
    async jwt({ token }) {
      return {
        id: token.id,
        name: token.name,
        email: token.email,
        role: token.role,
      };
    },


do i need a db call in jwt function?

im just a newbie just still learning hehe

1 Reply

Asiatic LionOP
btw im using CredentialsProvider