|
|
@ -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);
|
|
|
|
};
|
|
|
|
};
|
|
|
|