Created
November 8, 2019 02:59
-
-
Save bchiang7/186cf1a859c09b9af4eaea1bf8422d06 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
/** | |
* Check if a user has access to the app admin | |
*/ | |
const isAdmin = async (req, res, next) => { | |
if (req.headers && req.headers.authorization) { | |
if (!req.user || !req.user.isAdmin) { | |
return res.status(403).json({ message: 'You must have admin permissions.' }); | |
} | |
// If we get here, we're good so pass it along | |
next(); | |
} else { | |
const err = new Error('No auth headers set. You must have admin permissions.'); | |
// Pass the error to error handling middleware functions | |
next(err); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment