简体   繁体   English

(AngularJS + Passport)用户认证

[英]( 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的新手,我以{“ email”:“ gg@gmail.com”,“ password”:“ xxx”}的电子邮件和密码作为请求正文发送到服务器。在服务器端,我使用passportJS作为在https://github.com/jaredhanson/passport-local#available-options中

   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. 无法访问本地策略。应用程序崩溃,我仅收到TypeError:LocalStrategy需要验证回调。 Please let me know where i went wrong 请让我知道我错了

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 ). LocalStrategy包含可选options ,您可以在其中指定传递给服务器的POST正文中的参数(查找的默认参数为usernamepassword )。

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 只需在文档中指定您要在POST正文中传递的参数即可: https : //github.com/jaredhanson/passport-local#available-options

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM