Session library for NodeJS / HapiJS?

1

I'm doing an email application and got to the part where I need to do the session and login part, but I've never done it before, I'm using HapiJS as a server and I'd like to know which session libraries are best, and what other resources that I will need. If anyone can help me, I appreciate it.

Front-end: VueJS / Quasar

Server: HapiJS

    
asked by anonymous 24.08.2017 / 22:00

1 answer

1

PassportJS is a good login option and it is available for hapi . With express check if the user is logged in with intercept with express-session. I do not have the property to talk about hapi, but searching I saw that there is hapi-sesion .

Example

authenticator.js

module.exports = function(req, res, next) {
  if(!req.session.usuario) {
    return res.redirect('/');
  }
  return next();
};

route.js

var autenticar = require('autenticador');
router.get('/index', autenticar , function(req, res){

    res.status(200).json({
        mensagem: 'Logado!'
    });
});

This is an example with express and node, where the user is saved in the session in the successful callback of login and used in the routes. Likely that you need to adapt a bit to hapi or someone with that knowledge comes up here:)

    
24.08.2017 / 22:22