fix: API auth middleware for new auth system

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

@ -5,7 +5,7 @@
*/ */
import { Router, Request, Response, NextFunction } from 'express'; import { Router, Request, Response, NextFunction } from 'express';
import { users } from '../auth'; import { findFromToken, users } from '../auth';
import { data } from '../data'; import { data } from '../data';
const RouterApi = Router(); const RouterApi = Router();
@ -16,8 +16,8 @@ const RouterResource = Router();
* Token authentication middleware * Token authentication middleware
*/ */
const authMiddleware = (req: Request, res: Response, next: NextFunction) => { const authMiddleware = (req: Request, res: Response, next: NextFunction) => {
const token = req.headers.authorization; const user = findFromToken(req.headers.authorization ?? '');
(token && users[token]) (user && user.admin)
? next() ? next()
: res.sendStatus(401); : res.sendStatus(401);
}; };

Loading…
Cancel
Save