我正在尝试使用LocalStrategy向Passort进行身份验证。 问题在于该策略似乎从未被调用过,如果我将用户对象记录在我的护照中,对其进行身份验证将返回“ false”。
这是我的代码客户端:
Undefined symbols for architecture x86_64:
"std::_List_node_base::unhook()", referenced from:
std::list<Linphone::Conference::Participant,
std::allocator<Linphone::Conference::Participant>
>::remove(Linphone::Conference::Participant const&) in
liblinphone.a(conference.cc.o)
"std::_List_node_base::hook(std::_List_node_base*)", referenced from:
Linphone::Conference::addParticipant(_LinphoneCall*) in
liblinphone.a(conference.cc.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see
invocation)
这是策略:
logIn = () => {
const username = this.state.mail;
const password = this.state.password;
console.log("stringify " + JSON.stringify({username, password}));
fetch('http://localhost:3001/api/logIn',
{
method: 'POST',
headers: {'Content-Type': 'application/json'
/*'Access-Control-Allow-Origin': '*'*/},
body: JSON.stringify({username, password})
}).then(res => res.json()).then((res) => {
if (!res.success) console.log("fallito");
else console.log(res.username);
});
}
在此处拨打通行证。验证:
passport.use(new LocalStrategy(
{ usernameField: "mail" },
(username, password, done) => {
console.log("Inside localStrategy");
User.findOne({ mail: username.toLowerCase() }, (err, user) => {
if (err) {
console.log("not found " + err);
return done(err); }
if (!user) {
console.log("not users")
return done(undefined, false, { message: `Email ${mail} not found.` });
}
user.comparePassword(password, (err, isMatch) => {
if (err) {
console.log("password not correct " + err);
return done(err); }
if (isMatch) {
console.log("match");
return done(undefined, user);
}
console.log("invalid password")
return done(undefined, false, { message: "Invalid email or password." });
});
});
}));
请注意,我一直在尝试传递上面的代码中的User对象,并直接传递req var。
答案 0 :(得分:0)
在登录路径中,您正在使用passport.authenticate调用local
策略,但尚未创建local
策略。
请尝试
passport.use('local', new LocalStrategy(
代替
passport.use(new LocalStrategy(