到目前为止,我研究了stackoverflow关于在服务器重启后使会话持久化的答案.
我考虑用我的平均应用程序有4种可能的方式.
现在我的疑问是,我是否会在mongo和redis中重启我的服务器.会话仍然在那里,因为它们是外部数据存储.但是如何使用JWT和cookie会话使我的会话持久化.这些会话变量存储在何处.
在passport.js的情况下,我遇到的解决方案是使会话持久化是将会话数据存储在connect-mongo/connect-redis中.
护照中有没有其他方法可以使会话持续存在?
我想“注销时删除 cookie”。我不能那样做。我用谷歌搜索答案,发现以下方法:
为 cookie 分配新的到期日期
res.cookie('connect.sid', '', {expires: new Date(1), path: '/' });
使用以下行删除 cookie
res.clearCookie('connect.sid', { path: '/' });
我分别尝试了两种方法,但它们不会删除 cookie。
这是我的代码:
路由.js
module.exports = function(app, passport, session){
app.get('/', function(req, res)
{
res.render('index.ejs');
});
app.get('/login', function(req,res){
res.render('login.ejs',{message:req.flash('loginMessage')});
});
app.get('/signup',checkRedirect , function(req, res) {
res.render('signup.ejs',{message: req.flash('signupMessage')});
});
app.get('/profile', isLoggedIn, function(req,res) {
res.render('profile.ejs', {
user :req.user
});
});
app.post('/signup', passport.authenticate('local-signup', {
successRedirect : '/profile',
failureRedirect : '/signup',
failureFlash : true
}));
app.post('/login', passport.authenticate('local-login', {
successRedirect : '/profile',
failureRedirect : '/login',
failureFlash …Run Code Online (Sandbox Code Playgroud)