Session library for Nodejs/Hapijs?

Asked

Viewed 67 times

1

I’m making an email application and I got to the part where I need to do the session and login part, but I’ve never done this before, I’m using Hapijs as a server and I’d like to know which are the best session libraries, and also what other resources I’ll need. If anyone can help me I’d appreciate it.

Front-end: Vuejs/Quasar

Server: Hapijs

1 answer

1


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

Example

js authenticator.

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

js route.

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 callback successful of the login and used on the routes. Likely you need to adapt a little to the Hapi or come someone with this knowledge here :)

  • 1

    I’ll adapt for Hapi, I don’t know much about him either, but I’m learning. and with this part of the session implemented will greatly advance what I am doing. Thank you so much for helping me once again.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.