我正在使用 Express-Session 来设置带有 Redis 会话存储的会话 Cookie。当用户登录时,我可以成功设置一个 cookie,通过单击 chrome 中页面 URL 旁边的“锁定”图标并查看 cookie,将其登录,如图所示。然而,当页面刷新时,我的用户会因为 cookie 消失而注销。
如何防止页面刷新时丢失 cookie?
我的会话选项减去我的路线如下所示,我在 https 上运行我的客户端。
let sessionOptions = {
secret: "REDACTED_FROM_STACKOVERFLOW",
resave: true,
name: "redisSession",
expires: new Date(Date.now() + (60 * 1000 * 60 * 100000)),
store: new RedisStore({client: redisClient}),
cookie: {
sameSite: 'none',
secure: true,
httpOnly: true,
maxAge: 1000 * 60 * 1000
},
rolling: true,
saveUninitialized: true
};
app.use(cors({credentials: true, origin: 'https://localhost:8080'}));
const httpsOptions = {
key: fs.readFileSync(process.env.localHostCertKeyPath),
cert: fs.readFileSync(process.env.localHostPemPath)
}
app.use(cookieParser("REDACTED_FROM_STACKOVERFLOW"));
const httpsOptions …Run Code Online (Sandbox Code Playgroud)