Skip to content

Instantly share code, notes, and snippets.

@jwoyo
Last active January 20, 2020 21:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jwoyo/509b00edb9bea090d952e34a08ff9505 to your computer and use it in GitHub Desktop.
Save jwoyo/509b00edb9bea090d952e34a08ff9505 to your computer and use it in GitHub Desktop.
const restaurantOwnerOnlyMiddleware = (req, res, next) => {
const {restaurantId} = req.params; // in this case, the id is part of the path
const user = req.user; // available if you're using Google Firebase Authentication Middleware
const hasPermission = (id, user) => true; // do your checks here instead
if (!hasPermission(restaurantId, user)) {
res.status(403).send("Unauthorized");
return;
}
next(); // don't forget this. this will pass the request to the next middleware in the chain
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment