7

I am building a wrapper library 'auth-lib' for some existing(and out of my control) authentication libraries(for example keycloak-angular ). The authentication libraries I'm wrapping need to get initialized with configuration parameters during app initialization or bootstrapping which works when hard coding the configurations inside my Wrapper library but I can't get it to work with injection or forRoot from a sample application for my wrapper library.

How to pass the configuration parameters from my sample application through my wrapper library to the authentication libraries?

1 Answer 1

17

You can pass the configuration from App.Module using forRoot to your Library Module.

Try like this:

App.module.ts

 imports: [ BrowserModule, AuthLibModule.forRoot({ configuration: {configA : "abc", configB : "xyz"} }) ] 

AuthLibModule.module.ts

export class AuthLibModule{ static forRoot(configuration): ModuleWithProviders { console.log(configuration); return { ngModule: AuthLibModule, providers: [AuthLibService,{provide: 'config', useValue: configuration}] }; } } 

AuthLibService.service :

export class AuthLibService{ constructor(@Inject('config') private config:any) { console.log(config) } } 
Sign up to request clarification or add additional context in comments.

5 Comments

When I did that in a separate project, it worked; but moving it into my project doesn't so there is a problem with my project setup that I will need to figure out. Thank you for your answer.
Hey @Adrita - when I do this Argument Type (configuration: {configB: string, configA: string}} is not assignable to parameter type Routes. I've tried this many times and can't get around this error - something seems wrong with my syntax - any thoughts? I can post more code if that helps. Thank you
@Voltan Can you share your code in stackbiltz
@Adrita - thank you for response, Intellij was giving me a bogus error. All working now, so I'll close this.
@Voltan Great. If this helped you please upvote :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.