我目前正在开发一个 MERN 堆栈应用程序,我使用的身份验证是 JWT 并将其保存在我的 cookie 中。这就是我在用户登录后发送 cookie 的方式。
res
.cookie("token", token, {
httpOnly: true,
secure: true,
sameSite: "none",
})
.send();
Run Code Online (Sandbox Code Playgroud)
我通过在后端获取“令牌”cookie 来登录用户。然而,我用这个应用程序实现了 Redux,每次刷新页面时,它都会自动注销。我想要的是在我的前端(React)中检测浏览器中的“令牌”cookie,但我无法获取它。我尝试过使用 npm js-cookie 但仍然无法得到它。有没有办法获得“令牌”cookie?或者根据我读过的内容使用 redux-persist ?请帮忙,谢谢。