docs: add requireAdmin and docs for requireUser
This commit is contained in:
@@ -1,7 +1,20 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import { ErrorDTO } from "../schemas/miscSchema";
|
||||
import * as jwt from "../tools/jwt";
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { ErrorDTO } from '../schemas/miscSchema';
|
||||
import * as jwt from '../tools/jwt';
|
||||
|
||||
/**
|
||||
* Checks if user is singed in.
|
||||
* Returns 401 when user is unauthorized.
|
||||
*
|
||||
* To check if user is an admin, chain requireUser and requireAdmin together.
|
||||
* So: use requireUser first, and after that requireAdmin to enforce
|
||||
* admin privilege requirement.
|
||||
*
|
||||
* @param {Request} req The request
|
||||
* @param {Response} res The resource
|
||||
* @param {(Function|NextFunction)} next The next
|
||||
* @return {any} Next function on success, unauthorized error otherwise
|
||||
*/
|
||||
const requireUser = (req: Request, res: Response, next: NextFunction) => {
|
||||
const user: jwt.JwtStatus = res.locals.user;
|
||||
let error: ErrorDTO | null = null;
|
||||
@@ -38,4 +51,4 @@ const requireUser = (req: Request, res: Response, next: NextFunction) => {
|
||||
return next();
|
||||
};
|
||||
|
||||
export default requireUser;
|
||||
export default requireUser;
|
||||
|
||||
Reference in New Issue
Block a user