Skip to content

JWT module augmentation in next-auth v5 #9571

Description

@SornchaiTheDev

What is the improvement or update you wish to see?

next-auth v5 can't module augmentation at next-auth/jwt

Is there any context that might help us understand?

I've identified an error in the "Popular Interfaces to Augment" section of Next.js related to the JWT interface. It appears that the correct import should be @auth/core/jwt rather than next-auth/jwt. This correction is crucial because the jwt.d.ts file in the next-auth package includes a deprecated flag, signaling its replacement in version 5.

Screenshot 2567-01-07 at 2 43 19 PM

To illustrate this issue and its resolution, I've included screenshots:

Screenshot 1
Screenshot 2

Furthermore, when using next-auth with pnpm, there might be an issue where it can't locate @auth/core/jwt since it's a dependency of the next-auth package and resides in .pnpm within the node_modules directory. To address this, I've implemented the following solution:

// tsconfig.json
{
  "compilerOptions": {
        // Other options...
        "paths": {
         "@auth/core/*" : ["./node_modules/.pnpm/@auth+core@0.18.1/node_modules/@auth/core/*"]
        }
        // Other options...
  }
}

I've also submitted a pull request with these changes (#9563).

Does the docs page already exist? Please link to it.

https://authjs.dev/getting-started/typescript?frameworks=core

Metadata

Metadata

Assignees

No one assigned

    Labels

    docsRelates to documentationtriageUnseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions