I decided to implement a custom decorator for authentication across all controllers in my nest application. Here's the code snippet:
export function AuthRequired(exposeOptions?: ExposeOptions): (arg0: Controller, arg1: string, arg3: TypedPropertyDescriptor<unknown>) => void {
const exposeFn = Expose(exposeOptions);
const apiBearerAuthFn = ApiBearerAuth();
const guardFn = UseGuards(AuthGuard())
return function (target: Controller, key: string, descriptor: TypedPropertyDescriptor<unknown>): void {
apiBearerAuthFn(target, key, descriptor);
guardFn(target, key, descriptor);
exposeFn(target, key);
}
}
Unfortunately, after implementing this decorator, I noticed that all endpoints have unrestricted access. The Swagger interface appears like this: https://i.sstatic.net/R4z4v.png
The padlock icon indicating secured access is missing.
I'm seeking help to identify what might be causing this issue. Below is the complete code of my AuthService, AuthModule, AppModule, and AppController with the implemented AuthRequired decorator.
Any guidance on resolving this would be greatly appreciated!