style: fix linting issues met Prettier
This commit is contained in:
parent
7f670030a7
commit
0c47546814
30 changed files with 233 additions and 262 deletions
|
@ -1,9 +1,9 @@
|
|||
import {AuthenticationInfo} from "../authentication-info";
|
||||
import {AuthenticatedRequest} from "../authenticated-request";
|
||||
import * as express from "express";
|
||||
import {UnauthorizedException} from "../../../exceptions/unauthorized-exception";
|
||||
import {ForbiddenException} from "../../../exceptions/forbidden-exception";
|
||||
import {RequestHandler} from "express";
|
||||
import { AuthenticationInfo } from '../authentication-info';
|
||||
import { AuthenticatedRequest } from '../authenticated-request';
|
||||
import * as express from 'express';
|
||||
import { UnauthorizedException } from '../../../exceptions/unauthorized-exception';
|
||||
import { ForbiddenException } from '../../../exceptions/forbidden-exception';
|
||||
import { RequestHandler } from 'express';
|
||||
|
||||
/**
|
||||
* Middleware which rejects unauthenticated users (with HTTP 401) and authenticated users which do not fulfill
|
||||
|
@ -11,13 +11,17 @@ import {RequestHandler} from "express";
|
|||
* @param accessCondition Predicate over the current AuthenticationInfo. Access is only granted when this evaluates
|
||||
* to true.
|
||||
*/
|
||||
export function authorize<P,ResBody,ReqBody,ReqQuery,Locals extends Record<string, unknown>>(
|
||||
accessCondition: (auth: AuthenticationInfo, req: AuthenticatedRequest<P,ResBody,ReqBody,ReqQuery,Locals>) => boolean | Promise<boolean>
|
||||
): RequestHandler<P,ResBody,ReqBody,ReqQuery,Locals> {
|
||||
return async (req: AuthenticatedRequest<P,ResBody,ReqBody,ReqQuery,Locals>, _res: express.Response, next: express.NextFunction): Promise<void> => {
|
||||
export function authorize<P, ResBody, ReqBody, ReqQuery, Locals extends Record<string, unknown>>(
|
||||
accessCondition: (auth: AuthenticationInfo, req: AuthenticatedRequest<P, ResBody, ReqBody, ReqQuery, Locals>) => boolean | Promise<boolean>
|
||||
): RequestHandler<P, ResBody, ReqBody, ReqQuery, Locals> {
|
||||
return async (
|
||||
req: AuthenticatedRequest<P, ResBody, ReqBody, ReqQuery, Locals>,
|
||||
_res: express.Response,
|
||||
next: express.NextFunction
|
||||
): Promise<void> => {
|
||||
if (!req.auth) {
|
||||
throw new UnauthorizedException();
|
||||
} else if (!await accessCondition(req.auth, req)) {
|
||||
} else if (!(await accessCondition(req.auth, req))) {
|
||||
throw new ForbiddenException();
|
||||
} else {
|
||||
next();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue