Created
December 3, 2019 09:25
-
-
Save satishbabariya/25b09a366443daec63d594ad3e39f812 to your computer and use it in GitHub Desktop.
Is admin
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 user is admin or not | |
* @param {*} req Express req Object | |
* @param {*} res Express res Object | |
* @param {*} next Express next Function | |
*/ | |
const isAdmin = async (req, res, next) => { | |
if (!req.currentUser) { | |
return next(new Exception('Error in checking current user', 500)); | |
} | |
if (req.currentUser.role != Role.Admin) { | |
return next(new Exception('Insufficient permission', 403)); | |
} | |
return next(); | |
}; | |
export default isAdmin; | |
© 2019 GitHub, Inc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment