Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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);
}
Comment

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);
    });
  }
));
Comment

PREVIOUS NEXT
Code Example
Javascript :: react 
Javascript :: for loop on object js 
Javascript :: export default 
Javascript :: js ignore case 
Javascript :: add an object to index 0 array js 
Javascript :: javascript add 1 to each element in array 
Javascript :: calculate two number and diplay next field without reload the page javascript 
Javascript :: javascript remove required attribute 
Javascript :: date string to date in js 
Javascript :: convert object to url javascript 
Javascript :: how to refresh datatable in jquery 
Javascript :: how to deobfuscate javascript 
Javascript :: ion icon react 
Javascript :: date format in jquery 
Javascript :: Unable to resolve "@react-native-community/masked-view" from 
Javascript :: vue router transition 
Javascript :: this.setstate is not a function in react native 
Javascript :: cloudwatch logs sdk. 
Javascript :: remove object property javascript es6 
Javascript :: remove storybook from project 
Javascript :: set time in javascript 
Javascript :: javascript charcode 
Javascript :: javascript object type 
Javascript :: dot geometru three js 
Javascript :: monaco editor get value 
Javascript :: how to restablished closed rxjs websocket 
Javascript :: javascript Arrow Function with One Argumen 
Javascript :: JavaScript block-scoped Variable9 
Javascript :: onfocus 
Javascript :: google autocomplete not returning lat long 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =