Skip to content

Commit

Permalink
Merge pull request #21 from ciatph/dev
Browse files Browse the repository at this point in the history
v1.0.6
  • Loading branch information
ciatph committed Apr 7, 2022
2 parents f17dd26 + ca14a51 commit 0ad7288
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion server/src/middleware/superadmin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
const { ACCOUNT_LEVEL } = require('../utils/constants')

const isSuperAdmin = async (req, res, next) => {
if (req.user.account_level === ACCOUNT_LEVEL.SUPERADMIN) {
let level = 0

if (req.user.account_level) {
level = parseInt(req.user.account_level)
}

if (level === ACCOUNT_LEVEL.SUPERADMIN) {
next()
} else {
res.status(403).send('Unauthorized. Not a superadmin.')
Expand Down
4 changes: 2 additions & 2 deletions server/src/utils/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const ACCOUNT_LEVEL = {
SUPERADMIN: '1',
ADMIN: '2'
SUPERADMIN: 1,
ADMIN: 2
}

module.exports = {
Expand Down

0 comments on commit 0ad7288

Please sign in to comment.