cheatcode / joystick

A full-stack JavaScript framework for building stable, easy-to-maintain apps and websites.
https://cheatcode.co/joystick
Other
209 stars 11 forks source link

Add req.context.ifAuthorized() and req.context.ifNotAuthorized() redirects #346

Open rglover opened 1 year ago

rglover commented 1 year ago

Identical to behavior of req.context.ifLoggedIn and req.context.ifNotLoggedIn. API would look something like this:

req.context.ifAuthorized('role_to_check', '/route-if-has-role', () => {
  // Do this if they do not have the role.
});

req.context.ifNotAuthorized('role_to_check', '/route-if-not-has-role', () => {
  // Do this if they have the role.
});

Just need to account for NoSQL vs SQL queries when checking roles.