Search code examples
javascriptangularjspassport.jsmean-stackpassport-local

( AngularJS + Passport ) User authentication


I am new to Passport and I send email and password as {"email":"gg@gmail.com","password":"xxx"} as request body to the server.On server side,I make use of passportJS as in https://github.com/jaredhanson/passport-local#available-options like,

   passport.use(new LocalStrategy(
    {usernameField: 'email',
    passwordField: 'password',
    passReqToCallback: true
  },
    function(req,username,password,done){
      console.log("am here");
      var x=req.body;
      var email=x.email;
      var password=x.password;
      console.log(x.email);

}
))

app.post('/loginUser',passport.authenticate('local'),function(req,res){
   var x=req.body;
   db.users.findOne({"email":x.email,"password":x.password},function(err,user){
     res.json(user)
   })

 });

The Local Strategy isn't getting accessed.The application crashes and I only get TypeError: LocalStrategy requires a verify callback. Please let me know where i went wrong


Solution

  • The LocalStrategy includes optional options where you specify the parameters in the POST body passed to the server (the default parameters looked for are username and password).

    Just specify your parameters you're passing in your POST body here, as provided in the documentation: https://github.com/jaredhanson/passport-local#available-options