1

I created an Authentication Angular Library project to abstract the provider I'm using. Since angular library projects do not support environment configuration, I'm looking for a way for the consuming application project to be able to pass the configuration to the library project. I've seen people suggest implementing a forRoot method for the library's module, but I'm not sure how to use that in the NgModule decorator of the Authentication module. For example:

@NgModule({
  imports: [
    ProviderAuthModule.initAuth({
      issuer: config.issuer,
      redirectUri: `${config.rootURI}/implicit/callback`,
      clientId: config.clientID,
      responseType: config.responseType
    })
  ],
  declarations: [],
  exports: []
})
export class TdAuthenticationModule {
  static forRoot(config: ?) {
    return {
      ngModule: TdAuthenticationModule,
      ?
    };
  }
}

I've seen examples of folks using InjectorToken and being able to pass configuration to library projects that can then be injected into that library's services and components and whatnot, but I don't understand or know if there is a way to use what's passed into the library module in the decorator for that module.

Is this possible?

Jake Smith
  • 2,332
  • 1
  • 30
  • 68
  • No, it is not possible to do that. If you want to configure your module and use it inside of your of a decorator, consider setting an environment variable via environment.{env}.ts or via a .env (dotenv) file. – Michael Kang Sep 07 '18 at 02:32
  • angular libraries do not support environment files. dotenv might work, but I'm wondering if I made the right move in moving authentication concerns to a library project. I intended to reuse the same authentication for multiple applications, but the authentication needs to be configured depending on what environment I'm running. – Jake Smith Sep 07 '18 at 02:37

0 Answers0