0

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

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

That was indeed a good suggestion Lance , but still I get the same Type Error. I have updated the question on the same. Please let me know where i went wrong.
Hi..mistake was on my side with respect to importing package. THanks for your response.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.