nest-keycloak-connect icon indicating copy to clipboard operation
nest-keycloak-connect copied to clipboard

Cannot read properties of undefined (reading 'getAllAndOverride')

Open jose-with-an-accent opened this issue 9 months ago • 1 comments

We are simply loading the Keycloak config and declaring the guards in the providers:

imports: [
KeycloakConnectModule.registerAsync({
      useExisting: KeycloakConfigService,
      imports: [KeycloakConfigModule],
    })
],
providers: [
    {
      provide: APP_GUARD,
      useClass: AuthGuard,
    },
    {
      provide: APP_GUARD,
      useClass: ResourceGuard,
    },
    {
      provide: APP_GUARD,
      useClass: RoleGuard,
    },
  ],

We have a module and a service that configures the package:


//keycloak-config.module.ts
@Module({
  imports: [LoggingModule],
  providers: [KeycloakConfigService],
  controllers: [],
  exports: [KeycloakConfigService],
})
export class KeycloakConfigModule {}

// keycloak-config.service.ts
@Injectable()
export class KeycloakConfigService implements KeycloakConnectOptionsFactory {
  constructor(private readonly logger: HttpContextualLoggerService) {
    logger.info('Keycloak Config Service Started!')
  }
  createKeycloakConnectOptions(): KeycloakConnectOptions {
    return {
      authServerUrl: 'http://localhost:8080',
      realm: '...',
      clientId: '...',
      secret: null,
      policyEnforcement: PolicyEnforcementMode.PERMISSIVE,
      tokenValidation: TokenValidation.ONLINE,
    }
  }
}

We get the following error on an incoming request:

TypeError: Cannot read properties of undefined (reading 'getAllAndOverride')\n    at AuthGuard.<anonymous> (/Users/jsanchez/project/node_modules/nest-keycloak-connect/dist/guards/auth.guard.js:71:50)
   at Generator.next (<anonymous>)
    at /Users/jsanchez/project/node_modules/nest-keycloak-connect/dist/guards/auth.guard.js:43:71
    at new Promise (<anonymous>)
   at __awaiter (/Users/jsanchez/project/node_modules/nest-keycloak-connect/dist/guards/auth.guard.js:39:12)
    at AuthGuard.canActivate (/Users/jsanchez/project/node_modules/nest-keycloak-connect/dist/guards/auth.guard.js:69:16)
    at GuardsConsumer.tryActivate (/Users/jsanchez/project/node_modules/@nestjs/core/guards/guards-consumer.js:15:34)
    at canActivateFn (/Users/jsanchez/project/node_modules/@nestjs/core/router/router-execution-context.js:134:59)
    at /Users/jsanchez/project/node_modules/@nestjs/core/router/router-execution-context.js:42:37
    at /Users/jsanchez/project/node_modules/@nestjs/core/router/router-proxy.js:9:23"

@nestjs/common@npm:9.3.9 [1b2ba] (via npm:^9.0.0 [1b2ba])

jose-with-an-accent avatar May 01 '24 14:05 jose-with-an-accent