如何同时实施 LocalStrategy 和 CustomStrategy?

How to implement LocalStrategy and a CustomStrategy together?

我正在创建在线测验的应用程序。服务器端的技术堆栈是 node、express、passport、mongo 和 mongoose。客户端是Angular.

在这个应用中,我需要创建两种身份验证和会话。对于管理员,我需要在固定会话时间实施 LocalStrategy(用户名、密码)。对于候选人,一个带有个人会话和到期时间的 CustomStrategy (emailID)。

我该如何实现?

我同时使用了 CustomStrategy 和 LocalStrategy。

passport.use(new LocalStrategy({
    usernameField: 'email'
}, function(email, password, done) {
    User.findOne({
        email: email.toLowerCase()
    }, function(err, user) {
        if (!user) {
            return done(null, false, {
                msg: 'Email ' + email + ' not found.'
            });
        }
        user.comparePassword(password, function(err, isMatch) {
            if (isMatch) {
                return done(null, user);
            } else {
                return done(null, false, {
                    msg: 'Invalid email or password.'
                });
            }
        });
    });
}));



passport.use(new CustomStrategy(
    function(req, done) {
        Invite.findById(req.params.id, function(err, invite) {
            if (err) {
                console.log(err)
            }
            if (!invite) {
                return done(null, false, {
                    msg: 'Invite not found.'
                });
            }
            done(null, invite);
        });
    }
));