Passport local returns error 400 bad request with Angular

前端 未结 4 2227
庸人自扰
庸人自扰 2021-02-12 12:18

I am trying to integrate passport to my code\'s login form. Client side calling server side works as it should until i call passport.authenticate in the request, 400 Bad Request

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-12 12:44

    passport.use(new LocalStrategy(
        {
            usernameField: 'email',
            passwordField: 'password'
        },
        function (email, password, done) {
            db.collection('User').findOne({ email: email }, async function (err, user) {
                console.log('user requested password caught in passport', password);
                if (err) { return done(err); }
                if (!user) { return done(null, false); }
                const matchPassword = await comparePassword(password, user.password);
                if (!matchPassword) { return done(null, false); }
                return done(null, user);
            });
        }
    ));
    

提交回复
热议问题