I'm using APP_INITIALIZER to load environment specific variables. I need to use these variables inside of my authConfigFactory, but the factory keeps loading before APP_INITIALIZER has completed inside of the app config.
I'm using this library: https://github.com/manfredsteyer/angular-oauth2-oidc
I want to use the value of APP_CONFIG.authConfig.allowedUrls inside of my auth config factory. How can I make sure it sets the configuration first before the auth factory.
I get this error in the factory : Cannot read property 'authConfig' of undefined
app.module.ts:
providers: [
    AppConfigService,
    {
      provide: APP_INITIALIZER,
      useFactory: (config: AppConfigService) => () => config.load(),
      multi: true,
      deps: [AppConfigService]
    },
    {
      provide: OAuthModuleConfig,
      useFactory: authConfigFactory
    }
]
app.config.ts:
export let APP_CONFIG: AppConfig;
@Injectable()
export class AppConfigService {
  constructor(
    private injector: Injector
  ) {}
  config = null;
  public load() {
    const http = this.injector.get(HttpClient);
    return http
      .get('../assets/config/config.json')
      .pipe(
        tap(returnedConfig => {
          const t = new AppConfig();
          APP_CONFIG = Object.assign(t, returnedConfig);
        })
      )
      .toPromise();
  }
}
auth-config-factor:
export function authConfigFactory(): OAuthModuleConfig {
  return {
    resourceServer: {
      allowedUrls: APP_CONFIG.authConfig.allowedUrls,
      sendAccessToken: true
    }
  };
}