Next.js 中的 Cookie 被设置为空值

问题描述 投票:0回答:1

我正在尝试使用 Next.js 中的

cookies
函数设置 cookie,它在本地主机上工作得完全正常,但 cookie 值在生产中为空。此外,cookie 是由 Next.js 服务器本身设置的。我就是这样设置的:

const cookieStore = cookies();

cookieStore.set({
  name: "accessToken",
  value: res.data?.google?.access,
  httpOnly: true,
  secure: true,
  path: "/",
  maxAge: 3600,
  expires: new Date(Date.now() + 3600),
  sameSite: "strict",
});

cookieStore.set({
  name: "refreshToken",
  value: res.data?.google?.refresh,
  httpOnly: true,
  secure: true,
  path: "/",
  maxAge: 7 * 24 * 60 * 60,
  expires: new Date(Date.now() + 7 * 24 * 60 * 60),
  sameSite: "strict",
});

我尝试了这些解决方案:客户端未在生产中保存 cookie未在生产中设置 Cookie未在 Next.js 应用程序的生产中设置 Cookie。

这些解决方案都不适合我。

PS:我正在使用 Next.js V15 rc。

javascript next.js cookies production
1个回答
0
投票
我认为这是因为cookie是在收到请求之前设置的

© www.soinside.com 2019 - 2024. All rights reserved.