這個問題很明顯:我的瀏覽器上存儲了令牌。當我登錄時,服務器端認證中間件使用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');
}
}
想通了幾個小時回來,我工作的一個功能。如果您有興趣查看它,我會在找出修復程序時發佈該功能。 –