feat: added authorization for one api
This commit is contained in:
16
src/controller/utils/authorize.js
Normal file
16
src/controller/utils/authorize.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const UserRole = require("../../models/UserRole");
|
||||
const { AuthorizeUser } = require("../../config/auth");
|
||||
const { SUPER_ADMIN_ROLE, AUTHORIZATION_FAILURE_ERROR_MESSAGE } = require("../../config/constants");
|
||||
|
||||
module.exports = {
|
||||
SuperAdminCheck: async (req, res, next) => {
|
||||
const SuperAdmin = await UserRole.findOne({ name: SUPER_ADMIN_ROLE });
|
||||
if (AuthorizeUser(req.locals.user, [SuperAdmin.id])) {
|
||||
next();
|
||||
} else {
|
||||
res
|
||||
.status(403)
|
||||
.send({ success: false, error: AUTHORIZATION_FAILURE_ERROR_MESSAGE });
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user