You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m using next-auth@^5.0.0-beta.25, and I’m trying to extend the Session object according to the official documentation, but it doesn’t seem to be working as expected.
importNextAuth,{typeDefaultSession}from'next-auth'declare module 'next-auth'{/** * Returned by `auth`, `useSession`, `getSession` and received as a prop on the `SessionProvider` React Context */interfaceSession{user: {username: stringavatar: string}&DefaultSession['user']}}
I wrote the necessary code inside it and added the file to the include array in my tsconfig.json
However, the session object within the callback function is not returning the custom fields I defined as expected
callbacks: {/* * While using `jwt` as a strategy, `jwt()` callback will be called before * the `session()` callback. So we have to add custom parameters in `token` * via `jwt()` callback to make them accessible in the `session()` callback */asyncjwt({ token, user }){if(user){/* * For adding custom parameters to user in session, we first need to add those parameters * in token which then will be available in the `session()` callback */token.name=user.name}returntoken},asyncsession({ session, token, user }){console.log('Custom Session',session)if(session.user){// ** Add custom params to user in session which are added in `jwt()` callback via `token` parametersession.user.name=token.name}returnsession}}
I’ve been working on this for a whole day without any success. I need your help.
The text was updated successfully, but these errors were encountered:
xgbnl
added
bug
Something isn't working
triage
Unseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.
labels
Feb 27, 2025
@xgbnl you need to update the jwt submodule as well
see example below
// The `JWT` interface can be found in the `next-auth/jwt` submodule
import { JWT } from "next-auth/jwt"
declare module "next-auth/jwt" {
/** Returned by the `jwt` callback and `auth`, when using JWT sessions */
interface JWT {
/** OpenID ID Token */
idToken?: string
}
}
@xgbnl you need to update the jwt submodule as well
see example below
// The `JWT` interface can be found in the `next-auth/jwt` submodule
import { JWT } from "next-auth/jwt"
declare module "next-auth/jwt" {
/** Returned by the `jwt` callback and `auth`, when using JWT sessions */
interface JWT {
/** OpenID ID Token */
idToken?: string
}
}
Thank you, I have resolved this issue, and it helps me get the IDE to suggest the object’s properties. I encountered a new problem where using throw new Error('error content') in the authorize() method of version beta25 seems to not be caught when using the signIn() method in the Login.tsx component. Do you have any good solutions for this?
Environment
Reproduction URL
https://github.com/xgbnl/vuexy-kit-template
Describe the issue
I’m using next-auth@^5.0.0-beta.25, and I’m trying to extend the Session object according to the official documentation, but it doesn’t seem to be working as expected.
How to reproduce
next-auth.d.ts
Expected behavior
I’ve been working on this for a whole day without any success. I need your help.
The text was updated successfully, but these errors were encountered: