我正在尝试当地战略护照的一个例子。当我使用不正确的密码执行POST请求时(此时我只有一个db记录),它仍然最终执行我的成功函数:
componentWillReceiveProps(nextProps) {
const profileCandidateCollection = nextProps.profileCandidate;
const profileCandidateCollectionId = profileCandidateCollection._id;
const careerHistoryPositions = profileCandidateCollection && profileCandidateCollection.careerHistoryPositions;
console.log("componentWillReceiveProps: ", careerHistoryPositions);
if (careerHistoryPositions) {
const newData = careerHistoryPositions.map((position) =>
({
'uniqueId': position.uniqueId || '',
'company': position.company || '',
'title': position.title || ''
}));
this.setState({
data: newData
})
}
}
renderCareerPositions(props) {
if(0 < this.state.data.length) {
const careerPositions = this.state.data.map((position) =>
<CareerPosition
key={position.uniqueId}
companyName={position.company}
positionTitle={position.positionTitle}
uniqueId={position.uniqueId}
/>
);
return (
<ul>
{careerPositions}
</ul>
)
}
}
在passport.authenticate中定义。我哪里出错了?何时调用failureRedirect。
function (err, user) {
console.log("Login successful");
res.redirect('/loggedIn');
}
答案 0 :(得分:0)
尝试在passport.use
中使用此参数passport.use( new Strategy({usernameField: 'username',
passwordField: 'password',
session: false
},
function verify (username, password, done) {
users.findByUsername(username, function (err, user) {
if (err) { return done(err);}
if (!user) {return done(null, false);}
if (user.password != password) {return done(null, false);}
return done(null, user);
});