MadMax
MadMax
Explore posts from servers
TTCTheo's Typesafe Cult
Created by MadMax on 11/27/2023 in #questions
Getting role undefined in session even though it exist in db
interface UserRole {
role: "pleb" | "admin";
}

declare module "next-auth" {
interface Session extends DefaultSession {
user: {
id: string;
// ...other properties
role: UserRole;
} & DefaultSession["user"];
}

interface User {
// ...other properties
role: UserRole;
}
}

/**
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
*
* @see https://next-auth.js.org/configuration/options
*/
export const authOptions: NextAuthOptions = {
callbacks: {
session: ({ session, user }) => ({
...session,
user: {
...session.user,
id: user.id,
role: user.role,
},
}),
},
//@ts-ignored
adapter: DrizzleAdapter(db, mysqlTable),
providers: [
GoogleProvider({
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
}),
interface UserRole {
role: "pleb" | "admin";
}

declare module "next-auth" {
interface Session extends DefaultSession {
user: {
id: string;
// ...other properties
role: UserRole;
} & DefaultSession["user"];
}

interface User {
// ...other properties
role: UserRole;
}
}

/**
* Options for NextAuth.js used to configure adapters, providers, callbacks, etc.
*
* @see https://next-auth.js.org/configuration/options
*/
export const authOptions: NextAuthOptions = {
callbacks: {
session: ({ session, user }) => ({
...session,
user: {
...session.user,
id: user.id,
role: user.role,
},
}),
},
//@ts-ignored
adapter: DrizzleAdapter(db, mysqlTable),
providers: [
GoogleProvider({
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
}),
7 replies