Last active
February 21, 2024 15:54
-
-
Save vahidvdn/b04b04f3973e7644d22d6e341960bcb6 to your computer and use it in GitHub Desktop.
Custom Public Decorator instead of nestjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { SetMetadata } from '@nestjs/common'; | |
export const IS_PUBLIC_KEY = 'isPublic'; | |
export const Public0 = () => SetMetadata(IS_PUBLIC_KEY, true); // nestjs way | |
export const reflectObj = {}; | |
// custome way | |
export function Public() { | |
return function ( | |
target: any, | |
methodName: string, | |
descriptor: PropertyDescriptor, | |
) { | |
console.log('Public!', target, descriptor); | |
const className = target.constructor.name; | |
console.log(`Class name: ${className}`); | |
console.log(`Method name: ${methodName}`); | |
// defineMetadata can be used as well | |
reflectObj[className] = {}; | |
reflectObj[className][methodName] = true; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to access in the jwt guard: