@@ -38,10 +38,11 @@ export function UseGuards(
3838 propertyKey ?: string | symbol ,
3939 descriptor ?: PropertyDescriptor
4040 ) : void | PropertyDescriptor => {
41+ // For static methods, target is the constructor itself; for instance methods, it's the prototype
42+ const metadataTarget = typeof target === 'function' ? target : ( target as object ) . constructor ;
43+
4144 if ( propertyKey ) {
4245 // Method decorator - merge with existing guards and deduplicate
43- // For static methods, target is the constructor itself; for instance methods, it's the prototype
44- const metadataTarget = typeof target === 'function' ? target : ( target as object ) . constructor ;
4546 const existingGuards : ( Type < CanActivate > | CanActivate ) [ ] =
4647 Reflect . getMetadata ( GUARDS_METADATA , metadataTarget , propertyKey ) || [ ] ;
4748
@@ -55,9 +56,13 @@ export function UseGuards(
5556 } else {
5657 // Class decorator - merge with existing guards and deduplicate
5758 const existingGuards : ( Type < CanActivate > | CanActivate ) [ ] =
58- Reflect . getMetadata ( GUARDS_METADATA , target ) || [ ] ;
59+ Reflect . getMetadata ( GUARDS_METADATA , metadataTarget ) || [ ] ;
5960
60- Reflect . defineMetadata ( GUARDS_METADATA , [ ...new Set ( [ ...existingGuards , ...guards ] ) ] , target ) ;
61+ Reflect . defineMetadata (
62+ GUARDS_METADATA ,
63+ [ ...new Set ( [ ...existingGuards , ...guards ] ) ] ,
64+ metadataTarget
65+ ) ;
6166 return ;
6267 }
6368 } ;
0 commit comments