-
Notifications
You must be signed in to change notification settings - Fork 4k
Closed
Labels
docsRelates to documentationRelates to documentationtriageUnseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
Description
What is the improvement or update you wish to see?
next auth js provides documentation that does not work to augment the User interface in the @auth/core module.
Is there any context that might help us understand?
from the existing documentation we can augment the User interface like the method below
next-auth.d.ts
import { JWT } from '@auth/core/jwt'
import { type DefaultSession } from 'next-auth'
declare module '@auth/core' {
interface Session {
user: {
id: string
identifier: string
role: 'USER' | 'ADMIN'
name: string
} & DefaultSession['user']
}
interface User {
id: string
identifier: string
name: string
role: 'USER' | 'ADMIN'
}
}
declare module '@auth/core/jwt' {
interface JWT {
identifier: string
name: string
role: 'USER' | 'ADMIN'
}
}augment Session interface and JWT interface it works. but augment User interface does not work. my purpose of augmenting the User interface is to persist the role attribute on the User object, so that I can store it on the Session object.
auth.config.ts
import type { NextAuthConfig } from 'next-auth'
export const authConfig = {
callbacks: {
jwt({ token, user }) {
if (user) token.role = user.role // Property 'role' does not exist on type 'User | AdapterUser'. Property 'role' does not exist on type 'User'.ts(2339)
return token
},
session({ session, token }) {
session.user.role = token.role
return session
},
},
} satisfies NextAuthConfigDoes the docs page already exist? Please link to it.
https://authjs.dev/getting-started/typescript?frameworks=next
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
docsRelates to documentationRelates to documentationtriageUnseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.