2017-06-04 167 views
0

我是Passport的新手,我发送的电子邮件和密码为{“email”:“[email protected]”,“password”:“xxx”}作为服务器的请求主体。在服务器端,我利用passportJS的为https://github.com/jaredhanson/passport-local#available-options一样,(AngularJS +护照)用户身份验证

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

}); 

本地策略没有得到accessed.The应用程序崩溃,我只得到类型错误:LocalStrategy需要验证回调。请让我知道我出错的地方

回答

1

LocalStrategy包含可选的options,您可以在其中指定传递给服务器的POST正文中的参数(默认参数为usernamepassword)。

只要指定你的参数你传递你的POST主体在这里,如文档中提供:https://github.com/jaredhanson/passport-local#available-options

+0

这确实是一个很好的建议兰斯,但我仍然得到同样的类型错误。我已经更新了同样的问题。请让我知道我出错的地方。 – Gayathri

+0

嗨错误是在我的方面进口包。感谢您的答复。 – Gayathri