Skip to content

Secret is not cached #2

@fellmann

Description

@fellmann

Both guards are redefining the jwt functions on every call. In consequence, every API call leads to a new call to Auth0 - very bad for performance.

Looking at https://github.com/auth0-developer-hub/api_nestjs_typescript_hello-world/blob/main/src/authorization/authorization.guard.ts#L22, I think it should be:

...
export class AuthorizationGuard implements CanActivate {
  private validateAccessToken = promisify(auth());
  
  async canActivate(context: ExecutionContext): Promise<boolean> {
    const request = context.switchToHttp().getRequest<Request>();
    const response = context.switchToHttp().getResponse<Response>();

    try {
      await this.validateAccessToken(request, response);
...

Same for https://github.com/auth0-developer-hub/api_nestjs_typescript_hello-world/blob/main/src/authorization/permissions.guard.ts

Please do not use this repository as is.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions