Issue Setting up Dynamic Configuration

I am working on switching an Angular application to Auth0.
Currently working on deployment and needs dynamic configurations.

I followed this method:

function configInitializer(
  handler: HttpBackend,
  config: AuthClientConfig
) {
  return () =>
    new HttpClient(handler)
      .get('/config')
      .toPromise()
      // Set the config that was loaded asynchronously here
      .then((loadedConfig: any) => config.set(loadedConfig));
}

With this in my providers:

  providers: [
    {
      provide: APP_INITIALIZER,
      useFactory: configInitializer, // <- pass your initializer function here
      deps: [HttpBackend, AuthClientConfig],
      multi: true,
    },

When I try this I get the error of Configuration needs to be set AuthModule.forRoot() or AuthClientConfig.set.

When entering empty values on AuthModule.forRoot(), check the values before logging on to AuthService.
I find that the Auth0Client has no configuration set, and the Auth0COnfig does have the values.
The redirect goes to https:\authorization\ without my auth0 domain.

Thank you for your time.

Hi @rmejia,

Welcome to the Auth0 Community!

Make sure you also insert the imports like in the example below:

If you have any other questions feel free to reach out.

Have a good one,
Vlad

I found the solution. It wasn’t auth0, it was my application.
HttpBuilderService was calling my custom Auth.service.ts.
This causes a dependency on the auth0 AuthService, which my custom authservice uses.
My solution was to set up the dynamic configuration with the example and then with a separate method called after to inject the authservice instead of injecting at the constructor.

import { AuthService as auth0service } from “@auth0/auth0-angular”;

_auth: auth0Service
injector: Injector = inject(Injector);

int(){
this._auth = this.injector.get(auth0service);
}

thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.