【发布时间】:2016-05-23 03:33:48
【问题描述】:
这个问题不言自明:我的浏览器上存储了一个令牌。当我登录时,服务器端身份验证中间件使用 Passport 对我进行身份验证。但是,当我关闭并重新打开浏览器窗口时,令牌仍然存在,但 Passport 不知道我是谁。
如何将令牌从客户端检索到服务器端?
下面是我的代码。
app.get('/main', ensureAuthenticated, function(req, res, next) {
// thingToSend gets sent the first time, I will modify it
// later so it doesn't resend token if token exists
var thingToSend = {
token: createSendToken(req.user, config.secret),
id: req.user._id,
username: req.user.username,
authorization: req.user.authorization
};
res.render('main.ejs', thingToSend);
});
function ensureAuthenticated(req, res, next) {
if (req.isAuthenticated()) {
return next();
} else {
res.redirect('/login_page');
}
}
【问题讨论】:
标签: angularjs node.js token passport.js jwt