What I want to do is, that every time a user, registered or not, when requesting or entering a URL, I want to know what the user is, to see if he has access, and if he has it Render the page with the personal information of said user.
I tried to solve it by creating a controller
(called identifier) for each of the pages available on my website. Said controller is sending the client through res.send()
, header
with a script (ini.js).
The script, now if you send me the information through the user (id session, user id ...) using POST
. To a different controller effectively.
Now yes, I know who the user is, and if he has access or not, etc ... I want to redirect (res.redirect)
to the original page, the problem is that he re-executes the controller
(identifier ) then this becomes a cycle. (At the moment I do not render)
I do not know if there is a simpler solution to this problem. I've searched a lot but I can not find anything to help me.
EDITED:
Hello! Sorry for the delay I was working on this, and I think I have a solution, and it was with cookies, I do not know why I had the concept that LocalStorage was a replacement for cookies, but no, they have completely different functionality.
I show you the code of how I plan to solve it:
routes.js:
/*Todas las paginas pasan por un controller para ver quienes son*/
'get /registroUsuarios.html': 'AccesosController.accesos',
AccessesController.js:
module.exports = {
accesos: function(req, res) {
sails.log.info('----------------------------------');
sails.log.info('accesos()');
sails.log.info('----------------------------------');
res.cookie('codigo', '823789123798');
res.cookie('usuario', '12345667');
return res.view('registroUsuarios');
}
};
If for each request get
that is made to each page I can run the controller, I already allow myself to review permissions, and render. I think the only tedious thing at the moment is having to add all the routes of my page in routes.js
.
Let's see if someone serves you or has a suggestion. Greetings!
Thank you very much in advance