aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/middlewares/admin.js
blob: e6d9dc8878a7a4a3725e9f575121c4bef6a44b7a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
'use strict'

const constants = require('../initializers/constants')
const logger = require('../helpers/logger')

const adminMiddleware = {
  ensureIsAdmin
}

function ensureIsAdmin (req, res, next) {
  const user = res.locals.oauth.token.user
  if (user.role !== constants.USER_ROLES.ADMIN) {
    logger.info('A non admin user is trying to access to an admin content.')
    return res.sendStatus(403)
  }

  return next()
}

// ---------------------------------------------------------------------------

module.exports = adminMiddleware