部署环境中后端无法访问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
相关产品推荐
相关产品推荐

