Gayathri
Gayathri

Reputation: 1906

( AngularJS + Passport ) User authentication

I am new to Passport and I send email and password as {"email":"[email protected]","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

Upvotes: 0

Views: 79

Answers (1)

Lance Whatley
Lance Whatley

Reputation: 2455

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

Upvotes: 1

Related Questions