You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

部署环境中后端无法访问Cookies,req.cookies.jwt未定义

问题

本地环境中req.cookies.jwt能正常取值,但部署后该值始终为undefined。浏览器中已成功设置Cookies,仅后端无法访问该Cookie。尝试使用react-auth-kit仍未解决此问题。

验证代码
const token = req.cookies.jwt;
if (token) {
  jwt.verify(token, process.env.JWT_SECRET, async (err, decodedToken) => {
    if (err) {
      console.log("Wrong cookie");
      res.json({ status: false });
      return;
    } else {
      const currUser = await User.findById(decodedToken.id);
      if (currUser) {
        req.user = currUser;
        next();
      } else {
        res.json({ status: false });
        return;
      }
    }
  });
} else {
  console.log("no cookie");
  res.json({ status: false });
  return;
}

当前代码中token始终为undefined,完整代码可查看react-todo仓库。


内容的提问来源于stack exchange,提问作者pareshaann

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 14:36:00