diff --git a/src/routers/api.ts b/src/routers/api.ts index 5fdc92d..19159a2 100644 --- a/src/routers/api.ts +++ b/src/routers/api.ts @@ -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();