I am trying to restrict access to some elements on a web page for each kind of user after they pass their credentials through a login page.
The logic for accomplishing this is the following:
- The user enters their credentials on the login page.
- if the user enters the correct credentials nodejs will redirect to the dashboard
The following code is a partial code that shows how the users will be redirected to the dashboard endpoint (I prefer not to show the full code with complete validations in order to simplify this question)
// nodejs code in the server
app.post('/users/api', function(req, res) {
res.redirect('/dashboard');
}
I have in mind the following approach:
Together with the "res.redirect" send some headers to catch them when the dashboard.html page is ready (with JQuery ready function) and write some function for hiding elements on the page if the user has privileges or not.
The thing is that I've performed research but so far is not clear for me how to do this and if this is the correct approach.
Any help to build this code is welcome.