我正在使用 PassportJS,注册和登录功能运行得非常顺利。
我使用 PassportJS 面临的唯一问题(我也在使用会话),即使用户已经登录,他们也可以再次返回到注册/登录 url 并进行注册和/或重新登录!
这很诱惑我。如果有人有修复/建议,请把它写下来。
更新 - 1
我的一瞥routes.js
:(使用 PassportJS 和 connet-ensure-login。
app.get('*', function(req, res, next) {
if (req.url.indexOf('/users/login') < 0 &&
req.url.indexOf('/users/signup') < 0) {
req.session.returnTo = null;
}
next();
});
// =====================================
// HOME PAGE (with login links) ========
// =====================================
app.get('/', sabSettings, function(req, res) {
Setting.findOne(function(err, setting) {
if (err)
throw err;
// console.log(setting);
res.render('index', { title: 'eduBird | Reach the glory', setting: req.setting }); // load the index file
});
}); …
Run Code Online (Sandbox Code Playgroud)