1
0
Fork 0
peertube/server/middlewares/admin.ts

21 lines
515 B
TypeScript
Raw Normal View History

2017-06-10 16:15:25 -04:00
import 'express-validator'
import * as express from 'express'
2017-05-22 14:58:25 -04:00
import { logger } from '../helpers'
2017-06-10 16:15:25 -04:00
function ensureIsAdmin (req: express.Request, res: express.Response, next: express.NextFunction) {
const user = res.locals.oauth.token.user
2017-04-26 15:42:36 -04:00
if (user.isAdmin() === false) {
logger.info('A non admin user is trying to access to an admin content.')
return res.sendStatus(403)
}
return next()
}
// ---------------------------------------------------------------------------
2017-05-15 16:22:03 -04:00
export {
ensureIsAdmin
}