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
done(err)
which just returns if error occurs while processing.
done(null, false, {custom Message})
which means no error
but either email
or password
didn't matched.
done(null, user)
which means no error
and successful authentication
based on what is returned failureRedirect or successRedirect is decided
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.