expressjs护照登录错误

时间:2013-06-05 07:51:12

标签: express passport.js

我尝试使用带快递的护照。 passport.authenticate函数中的req.login函数触发错误,我真的不知道我做错了什么。

passport.use(new LocalStrategy({ usernameField: 'email' }, function (username, password, done) {

    userModel.findOne({ 'email': username }, function (err, user) {
        if (err) { return done(err); }
        if (!user) { return done(null, false, { message: 'Unknown email adress ' + username }); }
        user.comparePassword(password, function (err, isMatch) {
            if (err) return done(err);
            if (isMatch) {
                return done(null, user);
            } else {
                return done(null, false, { message: 'Invalid password' });
            }
        });
    });
}));

passport.authenticate('local', function (err, user, info) {
            if (err) {
                return res.send(401, "Invalid authentication");
            }

            if (!user) {
                return res.send(401, info.message);
            }

            req.login(user, function (err) {
                //console.log(user);
                console.log(err);
                if (err) {
                    return res.send(401, "Invalid authentication4");
                }
                return res.send(200, res);
            });
        })(req, res, next);  

浏览器显示警报Invalid authentication4,错误是req.login函数中的触发器。在shell console.log(错误)我是一个消息未定义[TypeError:将循环结构转换为JSON]

0 个答案:

没有答案