I am trying to make the page renderize the information of a user that is stored in res.locals
, however the router when rendering is in another file, therefore I can not get access to the res.locals
information.
// root.js
var express =require('express');
var router_app =require('./modulos/rutas');
var web =express();
web.use('/dashboard',router_app);
web.post('/login',function(entra,sale){ //AQUI INICIA EL LOGIN
valida.logIn(user).then((user)=>{
//Tiene que estar dentro de esta promesa puesto que tiene
//Guardar la informacion que retorna de esta promesa
sale.locals = {user : "Informacion Aqui"};
//Hasta aqui recibe bien la informacion
sale.redirect('/dashboard');
}).catch((error)=>{
console.log("Rechazado"+error);
});
});
So far we're doing fine.
//rutas.js
var express= require('express');
var router = express.Router();
router.get('/',(entra,sale)=>{
console.log(sale.locals);
//Aqui no imprime nada, la informacion ya no esta
});
module.exports = router;
Here the console does not print anything for me, simply the information that I saved before in locals
, is not ...
The idea that to save in locals
the id of a user to be able to search the information of said user and rende-rizar the page with all the information lowered of the BD
with respect to the user. I already have some time researching about res.locals
and I have not yet come to the solution of this problem.
I was reading that it has to do with what .render
calls .end
and that's why the .locals
information is removed.