# This PR - Addressing #3644 - Migrates the `DELETE /rest/*` endpoint to use TwentyORM - Factorizes common middleware logic into a common module --------- Co-authored-by: martmull <martmull@hotmail.fr>
29 lines
750 B
TypeScript
29 lines
750 B
TypeScript
import { Injectable, NestMiddleware } from '@nestjs/common';
|
|
|
|
import { NextFunction, Request, Response } from 'express';
|
|
|
|
import { MiddlewareService } from 'src/engine/middlewares/middleware.service';
|
|
|
|
@Injectable()
|
|
export class GraphQLHydrateRequestFromTokenMiddleware
|
|
implements NestMiddleware
|
|
{
|
|
constructor(private readonly middlewareService: MiddlewareService) {}
|
|
|
|
async use(req: Request, res: Response, next: NextFunction) {
|
|
if (this.middlewareService.checkUnauthenticatedAccess(req)) {
|
|
return next();
|
|
}
|
|
|
|
try {
|
|
await this.middlewareService.authenticateGraphqlRequest(req);
|
|
} catch (error) {
|
|
this.middlewareService.writeGraphqlResponseOnExceptionCaught(res, error);
|
|
|
|
return;
|
|
}
|
|
|
|
next();
|
|
}
|
|
}
|