/[sudobot]/branches/5.x/src/decorators/RequireAuth.ts
ViewVC logotype

Annotation of /branches/5.x/src/decorators/RequireAuth.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (hide annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months, 1 week ago) by rakinar2
File MIME type: application/typescript
File size: 737 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
1 rakinar2 577 import { NextFunction, Request, Response } from "express";
2     import type Controller from "../api/Controller";
3     import RequireAuthMiddleware from "../api/middleware/RequireAuthMiddleware";
4     import type Client from "../core/Client";
5    
6     export function RequireAuth(fetchUser = true) {
7     return (target: Controller, propertyKey: string, descriptor: PropertyDescriptor) => {
8     const metadata = Reflect.getMetadata("auth_middleware", target) ?? {};
9     const middleware = (client: Client, req: Request, res: Response, next: NextFunction) =>
10     RequireAuthMiddleware(client, fetchUser, req, res, next);
11    
12     metadata[propertyKey] ??= middleware;
13    
14     Reflect.defineMetadata("auth_middleware", metadata, target);
15     };
16     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26