As per my current requirement I need to create a library to authenticate user, I chose firebase for this purpose. User of this library is expected to provide environment variables that will initialise AngularFireModule from App.
SocialLoginLibModule (Library module installed)
import { AngularFireModule } from '@angular/fire';
//for testing environment variables were placed in the library
import { environment } from '../environments/environment';
import { AngularFireAuthModule } from '@angular/fire/auth';
import { AngularFirestoreModule } from '@angular/fire/firestore';
@NgModule({
declarations: [],
imports: [
CommonModule,
//Currently using local environment
//Need to get it from App
AngularFireModule.initializeApp(environment.firebase),
AngularFireAuthModule,
AngularFirestoreModule
],
providers: [],
exports: []
})
export class SocialLoginLibModule {
public static forRoot(environment:any): ModuleWithProviders {
return {
ngModule: SocialLoginLibModule,
providers: [
{
provide: 'env',
useValue: environment
}
]
}
}
};
I tried and successfully received the environment variables using the forRoot() method in the module, is there a possible way to use this. I cannot initialise AngularFireModule later in a service or a component as it gives Static-Injector Error. Can it be done via using OS Environment Variables or any other way.
PS: Started coding 6 months back please spare lack of technical jargon. Deliberately removed unnecessary imports.