护照 Js 不调用 isAuthenticated
Passportjs not calling isAuthenticate
我 运行 遇到一个问题,我的 index.js 文件尝试使用 passportjs 和 expressjs 调用 isAuthenticate() 。当我进行函数调用时,req.isAuthenticated() 永远不会被调用,并且总是 return false。
简要说明,我正在尝试对用户进行身份验证,以便他们可以访问他们有权查看的页面。
这是一个 link 到 repo https://github.com/SpotOnSoftwareInc/web-app
注意:这是我从别人那里继承的代码,其中很多工具对我来说都是新的。
'module.exports = function (passport) {
router.get('/login', login.get);
router.post('/login',passport.authenticate('local-login',{
//session: false,
successRedirect : '/registerprocess',
failureRedirect : '/register',
failureFlash: true
}));
function isLoggedInBusAdmin(req, res, next) {
//if user is authenticated in the session, carry on
if (req.isAuthenticated() && ((req.user[0].role === 'busAdmin') || (req.user[0].role === 'saasAdmin'))){
return next();
}
req.flash("permission", "You do not have permission to access that page");
// if they aren't redirect them to the home page
res.redirect('back');
}'
lib\auth.js
`function isAuthenticated(req, res, next) {
console.log('ENTERED IS AUTHENTICATED');
isValidToken(req.db, req.headers.authorization, function (result) {
if (!result) {
console.log('Not Authenticated');
return res.send(403);
} else {
req.mobileToken = result[0];
console.log('Authenticated PASS');
return next();
}
});
}
}`
在我的 app.js 文件
中发现错误
而不是调用
employee.find({_id: id}, 函数 (错误, 用户){
我在打电话
employee.findById({_id: id}, 函数(err, user){
我 运行 遇到一个问题,我的 index.js 文件尝试使用 passportjs 和 expressjs 调用 isAuthenticate() 。当我进行函数调用时,req.isAuthenticated() 永远不会被调用,并且总是 return false。 简要说明,我正在尝试对用户进行身份验证,以便他们可以访问他们有权查看的页面。
这是一个 link 到 repo https://github.com/SpotOnSoftwareInc/web-app
注意:这是我从别人那里继承的代码,其中很多工具对我来说都是新的。
'module.exports = function (passport) {
router.get('/login', login.get);
router.post('/login',passport.authenticate('local-login',{
//session: false,
successRedirect : '/registerprocess',
failureRedirect : '/register',
failureFlash: true
}));
function isLoggedInBusAdmin(req, res, next) {
//if user is authenticated in the session, carry on
if (req.isAuthenticated() && ((req.user[0].role === 'busAdmin') || (req.user[0].role === 'saasAdmin'))){
return next();
}
req.flash("permission", "You do not have permission to access that page");
// if they aren't redirect them to the home page
res.redirect('back');
}'
lib\auth.js
`function isAuthenticated(req, res, next) {
console.log('ENTERED IS AUTHENTICATED');
isValidToken(req.db, req.headers.authorization, function (result) {
if (!result) {
console.log('Not Authenticated');
return res.send(403);
} else {
req.mobileToken = result[0];
console.log('Authenticated PASS');
return next();
}
});
}
}`
在我的 app.js 文件
中发现错误而不是调用 employee.find({_id: id}, 函数 (错误, 用户){
我在打电话 employee.findById({_id: id}, 函数(err, user){