M
M
myspace2017-04-07 14:45:07
JavaScript
myspace, 2017-04-07 14:45:07

How to implement widgets with their own data in express?

For example, the moment with the menu, if a person is authorized, then he is shown a link to his personal account, and if not, then to the entrance / registration. Passing the isAuthorize(true|false) variable to all res.render() calls is not an option, I think. I would like to transfer it to something like a widget, so that only this logic is in it. Used by express+jade

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
emp1re, 2017-04-07
@myspace

Ask for session information the first time you open/refresh the page. And store it for example in localStorage. Concerning check on the server. If you use the passport, then it adds a session check method to the req body, if manually, write a midel var to check the session with each request.
It will not come to this if at the req stage you find out that the user is not authorized

app.get('/someUrl', isAuthorize, someController);
function isAuthorize(req, res, next){
// check user session
if(false) return res.send("you should login")
next();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question