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
docs: update to use provideAuth0 and provideAppInitializer
- Replace deprecated APP_INITIALIZER with provideAppInitializer
- Show provideAuth0() as primary configuration method
- Move NgModule examples to collapsible legacy sections
- Update for Angular 19+ best practices
Fixes#672
Copy file name to clipboardExpand all lines: README.md
+71-23Lines changed: 71 additions & 23 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
+
For modern Angular applications (v19+), use the functional `provideAuth0()` approach 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.
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`.
useFactory: configInitializer,// <- pass your initializer function here
168
+
useFactory: configInitializer,
123
169
deps: [HttpBackend, AuthClientConfig],
124
170
multi: true,
125
171
},
126
172
],
127
-
// ...
128
-
}
173
+
})
174
+
exportclassAppModule {}
129
175
```
130
176
177
+
</details>
178
+
131
179
### Add login to your application
132
180
133
181
To log the user into the application, inject the `AuthService` and call its `loginWithRedirect` method.
@@ -188,4 +236,4 @@ Please do not report security vulnerabilities on the public GitHub issue tracker
188
236
</p>
189
237
<p align="center">Auth0 is an easy to implement, adaptable authentication and authorization platform. To learn more checkout <a href="https://auth0.com/why-auth0">Why Auth0?</a></p>
190
238
<p align="center">
191
-
This project is licensed under the MIT license. See the <a href="https://github.com/auth0/auth0-angular/tree/main/LICENSE"> LICENSE</a> file for more info.</p>
239
+
This project is licensed under the MIT license. See the <a href="https://github.com/auth0/auth0-angular/tree/main/LICENSE"> LICENSE</a> file for more info.</p>
0 commit comments