0

I just started working on node using express framework.

app.use('/', auth, users);

and this is my route file

router.get('/' , function(req, res, next) {
   render("dashboard");
});

router.get('/first' , function(req, res, next) {
   //first request
});
router.get('/second' , function(req, res, next) {
   //second request
});
so on...

My question is, when i pass middleware it checks for every request whether its authenticated or not using passportjs, but suppose i have a dashboard and i am sending 10 ajax requests to grab data for the widgets. So only for dashboard it will call deserialize function 11 times ,first to render the page and then for 10 ajax request. I read answer given over here, How to properly use Passport.js? But is it fine to go with this approach?

1
  • You could also right a parallel call that handles the entire request - check the auth once first, then make the parallel call if auth is successful. Commented Oct 7, 2016 at 23:20

1 Answer 1

1

Yes, it is fine to go with this approach if you don't want to have security issues. You have to check the user for every request, it is very simple someone to check the network tab in the browser debugger, understand what's going on and then start spoofing your requests. You can't sacrifice security for performance because you want to execute few query less.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.