Authentication and Session PASSPORTJS

Here is the next part of the implementation of passport.js and express session.  To create a simple authentication with session, i would recommend the usage of these 3 libraries

  1. connect-ensure-login
  2. express-session
  3. passport

Main.js‘/login’, passport.authenticate(‘local’, {
  successReturnToOrRedirect: ‘/dashboard’,
  failureRedirect: ‘/login’
router.get(‘/applyuni’,connectEnsureLogin.ensureLoggedIn(),students.applyuni);‘/applyuni’,connectEnsureLogin.ensureLoggedIn(),students.applyuniform); //include validator
exports.dashboard = async (req,res)=>{
  const info = {
    ‘username’: req.user.username
The library ‘connect-ensure-login’ is super good. It really works well with passport.js. Once authenticated, the session will be stored. to access the session, just use the following sample command. “req.user.username”  With the session installed, you are able to create authorisation easily