2

The angular devtools plugin in firefox and chrome does not work and reports Angular application not detected. when the root path is guarded by a keycloak auth guard.

Reproduction steps:

  • Create a new angular project with ng new
  • Extend app.config.ts with keycloak configuration (see below)
  • In app.routes.ts add the following route:
{
    path: '',
    canActivate: [keycloakGuard],
    component: AppComponent
}

Now try to open angular devtools, on mac at least it does not work.

Is this worth adding to the 1.2k issues in the angular repo?

export function initializeKeycloak(
  keycloak: KeycloakService,
): () => Promise<boolean> {
  return () =>
      keycloak.init({
        config: {
          url: "<keycloak url>",
          realm: '<realm>',
          clientId: '<client id>',
        },
        initOptions: {
          checkLoginIframe: false,
        },
      });
}

const KeycloakBearerInterceptorProvider: Provider = {
  provide: HTTP_INTERCEPTORS,
  useClass: KeycloakBearerInterceptor,
  multi: true,
};

// Provider for Keycloak Initialization
const KeycloakInitializerProvider: Provider = {
  provide: APP_INITIALIZER,
  useFactory: initializeKeycloak,
  multi: true,
  deps: [KeycloakService],
};

export const appConfig: ApplicationConfig = {
  providers: [provideRouter(routes),
    provideHttpClient(withInterceptorsFromDi()),
    KeycloakInitializerProvider, // Initializes Keycloak
    KeycloakBearerInterceptorProvider, // Provides Keycloak Bearer Interceptor
    KeycloakService,
  ]
};
3
  • I have the same problem. I found out that it is about calling keycloak.init, not canActivate guard. If I remove the guard, devtools still dont work. If I don't call the APP_INITIALIZER provider, then devtools are back again. I tried to move keycloak.init to canActivate (making it async guard) but still devtools are broken. Commented Nov 1, 2024 at 11:38
  • seems you are right. Sadly, I did not have much more time to dig into this but its really annoying. Commented Nov 4, 2024 at 8:48
  • 2
    Of course it always makes sense to report the issue to the ones who actually can fix it possibly. I did so for the Keycloak package and for Angular DevTools itself. Commented Oct 28 at 11:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.