Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7612181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T01:50:44+00:00 2026-05-31T01:50:44+00:00

We have an application that has two types of users. Depending on how the

  • 0

We have an application that has two types of users. Depending on how the user logs in, we want them to have access to different parts of the application.

How do we implement a security model for preventing users from seeing things they do not have access to?

Do we make security part of each routes implementation? The problem being that we will have some duplicate logic across requests. We could move this into helper functions, but we’d still need to remember to call it.

Do we make security part of a global app.all() route handler? The problem being that we have to inspect each route and do different logic based on a multitude of rules. At least all the code is in one place, but then… all the code is in one place.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T01:50:45+00:00Added an answer on May 31, 2026 at 1:50 am

    Having it per-route usually works for me. This is what I typically do:

    function requireRole (role) {
        return function (req, res, next) {
            if (req.session.user && req.session.user.role === role) {
                next();
            } else {
                res.send(403);
            }
        }
    }
    
    app.get("/foo", foo.index);
    app.get("/foo/:id", requireRole("user"), foo.show);
    app.post("/foo", requireRole("admin"), foo.create);
    
    // All bars are protected
    app.all("/foo/bar", requireRole("admin"));
    
    // All paths starting with "/foo/bar/" are protected
    app.all("/foo/bar/*", requireRole("user"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that has two different login windows for two different types
I have an application that has many different types of objects that each persist
I'm developing a Rails 3 application that has two user types: Teacher and Company.
I'm developing a Rails 3 application that has two user types: Teacher and Company.
I'm designing an application that has two [three including administrators] user types: Buyers and
I have an application that has two threads. The first one (the main thread)
Is tight looping in a program bad? I have an application that has two
I have a Delphi 7 application that has two views of a document (e.g.
We have a WPF Application that has a two flavors with a consistent UI
I'm working on an application which has different types of users i.e. students, tutors,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.