i want to create middleware as decorator in nest js.
but problem is i dont want to create metadata.
and i have only one question how wrong is my solution ?
can i use it normally ?
export function Permission(required_permission: string) {
@Injectable()
class PermissionClass implements CanActivate {
canActivate(context: ExecutionContext): boolean {
const request = context.switchToHttp().getRequest();
// LOGIC ... if something throw new Unauthorized...
return true;
}
}
return applyDecorators(UseGuards(PermissionClass));
};
this is how use this decorator
export class AppController {
constructor(private readonly appService: AppService) {}
@Get()
@Permission("users:read")
isWorking(): string {
return this.appService.isWorking();
}
}
Expectations:
better solution or confirmation