[英]Passport authentication not working on Heroku?
我的應用程序是使用express的nodejs web應用程序。 它作為一個有cms和api的投資組合網站。
在我的登錄路線中,我有以下代碼:
passport.authenticate('local', function(err, user, info){
if(err){
return next(err);
} else if(!user){
res.format({
json: function(){
return error.throw403(req, res, next);
},
html: function(){
return res.redirect('/login');
}
});
} else {
console.log('login route, user');
console.log(user);
req.logIn(user, function(err){
if(err){
return next(err);
} else {
res.format({
json: function(){
return res.send(user);
},
html: function(){
return res.redirect('/cms/users');
}
});
}
});
}
})(req, res, next);
我的heroku日志告訴我用戶已定義且正確。 req.logIn()
觸發,成功並重定向(應該)到/cms/users
。 但是,由於req.user
不在請求中,因此我在/cms/users
處獲得403。 這讓我覺得我的會話並不堅持,但我不是專家,也不知道下一步該做什么。
我正在使用redistogo和mongolab,並且使用CLI設置了兩個配置。 有什么建議么? 我被卡住了! 謝謝。
編輯:我應該補充一點,在我的本地機器上一切正常。
文檔是我應該開始的地方。
https://devcenter.heroku.com/articles/redistogo#using-with-node-js
我按照該網站上的每個配置跟隨該字母,然后調整應用程序配置順序,直到它工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.