Tell us what’s happening:
It displays ‘Can’t POST /login’ athte page after sumitting the login form for this tutorial:
Advanced Node and Express - How to Use Passport Strategies
can some1 help plz?!
Your code so far
the added code at server.js :
app.route('/login')
.post(passport.authenticate('local', { failureRedirect: '/' }),(req,res) => {
res.redirect('/profile');
});
});
passport.use(new LocalStrategy(
function(username, password, done) {
myDataBase.findOne({ username: username }, function (err, user) {
console.log('User '+ username +' attempted to log in.');
if (err) { return done(err); }
if (!user) { return done(null, false); }
if (password !== user.password) { return done(null, false); }
return done(null, user);
});
}
));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
.
Challenge: How to Use Passport Strategies
Link to the challenge: