Skip to content

Instantly share code, notes, and snippets.

@satishbabariya
Created December 3, 2019 09:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satishbabariya/25b09a366443daec63d594ad3e39f812 to your computer and use it in GitHub Desktop.
Save satishbabariya/25b09a366443daec63d594ad3e39f812 to your computer and use it in GitHub Desktop.
Is admin
/**
* 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