Skip to content

Support Next.js Version 13.0.1 #5701

@HaNdTriX

Description

@HaNdTriX

Description 📓

Next.js 13.0.1 introduces the following breaking change: vercel/next.js#41526

TLTR: Before request.cookies.get(<name>) returned the cookie value. Now this invocation returns the following object:

{ name: <name>, value: <value>}

resulting in jwt.getToken to always return null

How to reproduce ☕️

Node.js Example (Works)

import type { NextApiRequest, NextApiResponse } from "next";
import { getToken } from "next-auth/jwt";

export default async function handler(
  req: NextApiRequest,
  res: NextApiResponse
) {
  const token = await getToken({ req, secret: process.env.NEXTAUTH_SECRET });
  res.status(200).json({ token });
}

This code returns the correct token.

Edge Example (Doesn't work)

import type { NextRequest } from "next/server";
import { getToken } from "next-auth/jwt";

export const config = {
  runtime: "experimental-edge",
};

export default async function handler(req: NextRequest) {
  const token = await getToken({ req, secret: process.env.NEXTAUTH_SECRET });
  return new Response(
    JSON.stringify({
      token,
    }),
    {
      status: 200,
      headers: {
        "content-type": "application/json",
      },
    }
  );
}

This code always returns token: null.

System Info

  • Used Next.js Version: 13.0.1

Related Code

if (cookies instanceof Map) {
for (const name of cookies.keys()) {
if (name.startsWith(cookieName)) this.#chunks[name] = cookies.get(name)
}
} else {
for (const name in cookies) {
if (name.startsWith(cookieName)) this.#chunks[name] = cookies[name]
}
}

Contributing 🙌🏽

Yes, I am willing to help implement this feature in a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesttriageUnseen 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