不调用的 Passportjs 是身份验证

Passportjs not calling isAuthenticate

本文关键字:身份验证 Passportjs 调用      更新时间:2023-09-26

我的索引.js文件遇到问题,试图使用带有expressjs的passportjs调用isAuthenticate()。当我进行函数调用时,req.isAuthenticated() 永远不会被调用,并且总是返回 false。简要说明,我正在尝试对用户进行身份验证,以便他们可以访问他们有权查看的页面。

这是回购 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();
        }
    });
}
}`

在我的应用程序.js文件中发现错误

而不是打电话employee.find({_id: id}, function (err, user){

我在打电话employee.findById({_id: id}, function (err, user){