我正在尝试使用 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。