feat: add middleware function for verifying admin users

pull/177/head
tycrek 2 years ago
parent 6c9b8166e9
commit ac8c861bb1
No known key found for this signature in database
GPG Key ID: FF8A54DCE404885A

@ -7,9 +7,20 @@
import { Router, Request, Response, NextFunction } from 'express';
import { findFromToken, users } from '../auth';
import { data } from '../data';
import { User } from '../types/auth';
/**
* The primary API router
*/
const RouterApi = Router();
/**
* Token authentication middleware for Admins
*/
const adminAuthMiddleware = (req: Request, res: Response, next: NextFunction) => {
const user = findFromToken(req.headers.authorization ?? '');
(user && user.admin) ? next() : res.sendStatus(401);
};
function buildUserRouter() {
const RouterUser = Router();

Loading…
Cancel
Save