title: Routing a service with different access levels
body: <p>Hi I'm creating a project for school and I don't know how to properly route my project. May I borrow your help?</p>
  <p>Currently, the project has 3 routers and 3 db users (+ 1 for login):</p>
  <pre class="lang-js prettyprint-override"><code>router.use(/^\/admin/, auth.verifyJWTMiddleWare, adminRouter);
  router.use(/^\/user-2/, auth.verifyJWTMiddleWare, user1Router);
  router.use(/^\/user-1/, auth.verifyJWTMiddleWare, user2Router);
  </code></pre>
  <p>I have 3 users and many services, and taking a example of service &quot;<code>Service</code>&quot;</p>
  <ul>
  <li>Admin has access to all routes of <code>Service</code></li>
  <li>User 2 has access to most routes from <code>Service</code></li>
  <li>User 1 has limited access to <code>Service</code></li>
  </ul>
  <p>This causes the code to repeat as the users have shared actions.</p>
  <p><a href="https://i.stack.imgur.com/SUCTz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SUCTz.png" alt="enter image description here" /></a></p>
  <p>But I don't want to create a validation for each route for every user</p>
  <pre class="lang-js prettyprint-override"><code>router.get(/\/anything/, async (req, res)=&gt; {
      if(req.rol === 'user1')
          return res.status(403).end();
      if(req.rol === 'user2')
          return res.status(403).end();
  
      return res.status(200).send({msg: 'You are the admin'});
  });
  </code></pre>
  <p>What should I do to get an authenticator to give me the corresponding access according to the user?</p>
  <p><a href="https://i.stack.imgur.com/hqagr.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hqagr.png" alt="enter image description here" /></a></p>
  <p>I was thinking in exporting the routes. Something like:</p>
  <pre class="lang-js prettyprint-override"><code>module.exports = {
      admin: [
          route1,
          route2,
          route3,
          route4,
          route5,
          route6
      ],
      user2: [
          route1,
          route2,
          route3,
          route4
      ],
      user1: [
          route1,
          route2
      ],
  }
  </code></pre>
  <p>But I don't know how to save the route on a variable or even if it's possible, and then, how to use that array. Would it be something like this? Is this secure?</p>
  <pre><code>const serviceRouter = require('./routers/service');
  
  router.use(/^\/admin/, auth.verifyJWTMiddleWare, serviceRouter.admin);
  </code></pre>
  <p>How can I achieve this behavior</p>