Skip to content

Instantly share code, notes, and snippets.

@mpragnarok
Created September 12, 2019 02:27
Show Gist options
  • Save mpragnarok/2ec5fed0167a61c87d65d7f974c96909 to your computer and use it in GitHub Desktop.
Save mpragnarok/2ec5fed0167a61c87d65d7f974c96909 to your computer and use it in GitHub Desktop.
message setting in the user router
// src\routers\user.js
// show login page
router.get('/login', async (req, res) => {
try {
res.render('login', { message: req.flash('error') })
} catch (e) {
res.status(500).send()
}
})
// login authentication
router.post('/login', async (req, res, next) => {
try {
passport.authenticate('local', {
successRedirect: '/',
failureRedirect: '/users/login',
badRequestMessage: 'The email does not match any account', // change "missing credentials" message
failureFlash: true
})(req, res, next)
} catch (e) {
res.status(400).send()
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment