Answers for "passport js local strategy response handling"

0

passport js local strategy response handling

exports.isLocalAuthenticated = function(req, res, next) {
    passport.authenticate('local', function(err, user, info) {
        if (err) { return next(err); } //error exception

        // user will be set to false, if not authenticated
        if (!user) {
            res.status(401).json(info); //info contains the error message
        } else {
            // if user authenticated maintain the session
            req.logIn(user, function() {
                // do whatever here on successful login
            })
        }    
    })(req, res, next);
}
Posted by: Guest on September-28-2020
0

passport local strategy

passport.use(new LocalStrategy(
  function(username, password, done) {
    User.findOne({ username: username }, function (err, user) {
      if (err) { return done(err); }
      if (!user) { return done(null, false); }
      if (!user.verifyPassword(password)) { return done(null, false); }
      return done(null, user);
    });
  }
));
Posted by: Guest on June-14-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language