|
|
@ -7,9 +7,20 @@
|
|
|
|
import { Router, Request, Response, NextFunction } from 'express';
|
|
|
|
import { Router, Request, Response, NextFunction } from 'express';
|
|
|
|
import { findFromToken, users } from '../auth';
|
|
|
|
import { findFromToken, users } from '../auth';
|
|
|
|
import { data } from '../data';
|
|
|
|
import { data } from '../data';
|
|
|
|
|
|
|
|
import { User } from '../types/auth';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* The primary API router
|
|
|
|
|
|
|
|
*/
|
|
|
|
const RouterApi = 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() {
|
|
|
|
function buildUserRouter() {
|
|
|
|
const RouterUser = Router();
|
|
|
|
const RouterUser = Router();
|
|
|
|
|
|
|
|
|
|
|
|