简体   繁体   中英

How passport.authenticate() determine successRdirect or failureRedirect?

I beginner to nodejs and trying to apply authentication using (passport,passport-local) and using local strategy.in local strategy i check email and password and compare it with database record.if email and password is correct I return done(null, user) call back.Then in passport.authenticate() how it determines to redirect to failureRedirect or successRedirect?

router.post('/login', passport.authenticate('local',
{
        successRedirect: '/',
        failureRedirect: '/login'
}

));

While Authenticating with passport . Strategies require what is known as a verify callback . The purpose of a verify callback is to find the user that possesses a set of credentials.

You can return 3 types of callback result

  1. done(err) which just returns if error occurs while processing.

  2. done(null, false, {custom Message}) which means no error but either email or password didn't matched.

  3. done(null, user) which means no error and successful authentication

based on what is returned failureRedirect or successRedirect is decided

More Info Here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM