Skip to content

Commit

Permalink
fix(core): multiple guard decorators bug
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayak25 committed Jan 17, 2025
1 parent 41e9823 commit 2adf084
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 2 additions & 4 deletions integrations/sample-app/app/http/controllers/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ export class IntentController {
return { hello: 'world' };
}

@Post('/json')
@Validate(LoginDto)
@UseGuards(CustomGuard)
@Post('/json')
async postJson(
@Req() req: Request,
@Dto() dto: LoginDto,
Expand Down Expand Up @@ -131,9 +132,6 @@ export class IntentController {
// userAgent,
// );

// console.log('all headers ===> ', headers);
console.log('uploaded files ==> ', req.dto(), dto);

const readStream = createReadStream(
join(findProjectRoot(), 'storage/uploads/sample-image.jpg'),
);
Expand Down
8 changes: 6 additions & 2 deletions packages/core/lib/rest/http-server/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,14 @@ export const ANY: RouteDecoratorType = (
export const UseGuards = (...guards: Type<IntentGuard>[]) => {
return function (target: object, key?: string | symbol, descriptor?: any) {
if (key) {
Reflect.defineMetadata(GUARD_KEY, guards, target, key);
const existingGuards = Reflect.getMetadata(GUARD_KEY, target, key);
const composeGuards = [...(existingGuards || []), ...guards];
Reflect.defineMetadata(GUARD_KEY, composeGuards, target, key);
return;
}
Reflect.defineMetadata(GUARD_KEY, guards, target);
const existingGuards = Reflect.getMetadata(GUARD_KEY, target);
const composeGuards = [...(existingGuards || []), ...guards];
Reflect.defineMetadata(GUARD_KEY, composeGuards, target);
return;
};
};

0 comments on commit 2adf084

Please sign in to comment.