Created
March 28, 2021 16:08
-
-
Save dsebastien/b3e0d7e39437e5a1c589f02436d25252 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// app.module.ts | |
// --------------------------- | |
import { AuthModule, AuthClientConfig } from '@auth0/auth0-angular'; | |
// Provide an initializer function that returns a Promise | |
function configInitializer( | |
handler: HttpBackend, | |
config: AuthClientConfig | |
) { | |
return () => | |
new HttpClient(handler) | |
.get('/config') | |
.toPromise() | |
.then((loadedConfig: any) => config.set(loadedConfig)); // Set the config that was loaded asynchronously here | |
} | |
// Provide APP_INITIALIZER with this function. Note that there is no config passed to AuthModule.forRoot | |
imports: [ | |
// other imports.. | |
HttpClientModule, | |
AuthModule.forRoot(), //<- don't pass any config here | |
], | |
providers: [ | |
{ | |
provide: APP_INITIALIZER, | |
useFactory: configInitializer, // <- pass your initializer function here | |
deps: [HttpBackend, AuthClientConfig], | |
multi: true, | |
}, | |
], |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment