You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+70-22Lines changed: 70 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -64,14 +64,35 @@ Take note of the **Client ID** and **Domain** values under the "Basic Informatio
64
64
65
65
#### Static configuration
66
66
67
-
Install the SDK into your application by importing `AuthModule.forRoot()` and configuring with your Auth0 domain and client id, as well as the URL to which Auth0 should redirect back after succesful authentication:
67
+
The recommended approach is to use the functional `provideAuth0()` in your application configuration:
If you're using NgModules, you can configure the SDK using `AuthModule.forRoot()`:
68
90
69
91
```ts
70
92
import { NgModule } from'@angular/core';
71
93
import { AuthModule } from'@auth0/auth0-angular';
72
94
73
95
@NgModule({
74
-
// ...
75
96
imports: [
76
97
AuthModule.forRoot({
77
98
domain: 'YOUR_AUTH0_DOMAIN',
@@ -81,53 +102,80 @@ import { AuthModule } from '@auth0/auth0-angular';
81
102
},
82
103
}),
83
104
],
84
-
// ...
85
105
})
86
106
exportclassAppModule {}
87
107
```
88
108
109
+
</details>
110
+
89
111
#### Dynamic configuration
90
112
91
-
Instead of using `AuthModule.forRoot` to specify auth configuration, you can provide a factory function using `APP_INITIALIZER` to load your config from an external source before the auth module is loaded, and provide your configuration using `AuthClientConfig.set`.
113
+
Instead of providing static configuration, you can use `provideAppInitializer` to load your config from an external source before the SDK is instantiated, and configure it using `AuthClientConfig.set`.
92
114
93
-
The configuration will only be used initially when the SDK is instantiated. Any changes made to the configuration at a later moment in time will have no effect on the default options used when calling the SDK's methods. This is also the reason why the dynamic configuration should be set using an `APP_INITIALIZER`, because doing so ensures the configuration is available prior to instantiating the SDK.
> :information_source: Any request made through an instance of `HttpClient` that got instantiated by Angular, will use all of the configured interceptors, including our `AuthHttpInterceptor`. Because the `AuthHttpInterceptor` requires the existence of configuration settings, the request for retrieving those dynamic configuration settings should ensure it's not using any of those interceptors. In Angular, this can be done by manually instantiating `HttpClient` using an injected `HttpBackend` instance.
> **Important:** The configuration will only be used initially when the SDK is instantiated. Any changes made to the configuration at a later moment in time will have no effect on the default options used when calling the SDK's methods. This is why the dynamic configuration should be set using an app initializer, which ensures the configuration is available prior to instantiating the SDK.
142
+
143
+
> :information_source: Any request made through an instance of `HttpClient` that got instantiated by Angular will use all configured interceptors, including our `AuthHttpInterceptor`. Because the `AuthHttpInterceptor` requires the existence of configuration settings, the request for retrieving those dynamic configuration settings should ensure it's not using any interceptors. In Angular, this can be done by manually instantiating `HttpClient` using an injected `HttpBackend` instance.
144
+
145
+
<details>
146
+
<summary>Using NgModules</summary>
96
147
97
-
```js
148
+
Instead of using `AuthModule.forRoot` to specify auth configuration, you can provide a factory function using `APP_INITIALIZER` to load your config from an external source before the auth module is loaded, and provide your configuration using `AuthClientConfig.set`.
0 commit comments