Skip to content

Error when custom jwt method #5704

@kidp2h

Description

@kidp2h

Environment

System:
OS: Linux 5.19 Debian GNU/Linux 10 (buster) 10 (buster)
CPU: (12) x64 AMD Ryzen 5 5600H with Radeon Graphics
Memory: 123.65 MB / 5.65 GB
Container: Yes
Shell: 5.0.3 - /bin/bash
Binaries:
Node: 16.13.2 - /usr/local/bin/node
Yarn: 1.22.15 - /usr/local/bin/yarn
npm: 8.1.2 - /usr/local/bin/npm
npmPackages:
next: ^13.0.0 => 13.0.0
next-auth: ^4.15.0 => 4.15.0
react: 18.2.0 => 18.2.0

Reproduction URL

https://github.com/nextauthjs/next-auth-example

Describe the issue

I follow this tutorial in official document next-auth, when i custom jwt method ( encode, decode )

NextAuthOptions: pages/api/auth/[...nextauth].ts

jwt: {
  maxAge: 60 * 60 * 24 * 14,
  async encode({ token: payload, secret }) {
    return jwt.sign(payload, secret);
  },
  async decode({ token, secret }) {
    return jwt.verify(token, secret) as any;
  },
}

and pass decode method above to middleware

middleware.ts

and i got error
image

How to reproduce

  1. Clone https://github.com/nextauthjs/next-auth-example
  2. Replace jwt options with above options and pass jwt decode to middleware
  3. Access localhost:3000 and login

Expected behavior

Can get token in middleware when use custom jwt method

Metadata

Metadata

Assignees

No one assigned

    Labels

    triageUnseen or unconfirmed by a maintainer yet. Provide extra information in the meantime.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions