I'm currently attempting to implement passport authentication within my express application.
router.get('/register', (req, res) => {
res.render('register');
});
router.post('/register', function(req, res, next) {
var username = req.body.username;
var password = req.body.password;
User.findOne({ username: username }, function(err, user) {
if(err) { return next(err); }
if(user) {
req.flash('error', 'User already exists');
return res.redirect('/register');
}
var newUser = new User({
username: username,
password: password
});
newUser.save(next);
});
}, passport.authenticate('local', {
successRedirect: '/',
failureRedirect: '/register',
failureFlash: true
}));
Although signing up a test user seems to work, I keep encountering the following error:
Error: Unknown authentication strategy "local"
Do you have any advice or suggestions on how to resolve this issue?