Last active
January 20, 2020 21:49
-
-
Save jwoyo/509b00edb9bea090d952e34a08ff9505 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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