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
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:resulting in
jwt.getTokento always returnnullHow to reproduce ☕️
Node.js Example (Works)
This code returns the correct token.
Edge Example (Doesn't work)
This code always returns
token: null.System Info
13.0.1Related Code
next-auth/packages/next-auth/src/core/lib/cookie.ts
Lines 143 to 151 in 30ad639
Contributing 🙌🏽
Yes, I am willing to help implement this feature in a PR