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 :)
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.
– LeonardoEbert