aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/middlewares/admin.ts
blob: 812397352c6d62588297f64ef6227f7c44fb38fb (plain) (tree)
1
2
3
4
5
6
7
8


                                  
                                   
 
                                                                                                  
                                          
                                 








                                                                              


               
import 'express-validator'
import * as express from 'express'

import { logger } from '../helpers'

function ensureIsAdmin (req: express.Request, res: express.Response, next: express.NextFunction) {
  const user = res.locals.oauth.token.user
  if (user.isAdmin() === false) {
    logger.info('A non admin user is trying to access to an admin content.')
    return res.sendStatus(403)
  }

  return next()
}

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

export {
  ensureIsAdmin
}