|
8 | 8 | - [Call an API](#call-an-api) |
9 | 9 | - [Handling errors](#handling-errors) |
10 | 10 | - [Organizations](#organizations) |
| 11 | +- [Standalone Components and a more functional approach](#standalone-components-and-a-more-functional-approach) |
11 | 12 |
|
12 | 13 | ## Add login to your application |
13 | 14 |
|
@@ -378,3 +379,37 @@ export class AppComponent { |
378 | 379 | } |
379 | 380 | } |
380 | 381 | ``` |
| 382 | +
|
| 383 | +## Standalone components and a more functional approach |
| 384 | +As of Angular 15, the Angular team is putting standalone components, as well as a more functional approach, in favor of the traditional use of NgModules and class-based approach. |
| 385 | +
|
| 386 | +There are a couple of difference with how you would traditionally implement our SDK: |
| 387 | +
|
| 388 | +- Use our functional guard (`authGuardFn`) instead of our class-based `AuthGuard`. |
| 389 | +- Use our functional interceptor (`authHttpInterceptorFn`) instead of our class-based `AuthHttpInterceptor`. |
| 390 | +- Register the interceptor by passing it to `withInterceptors` when calling `provideHttpClient`. |
| 391 | +- Register our SDK using `provideAuth0`. |
| 392 | +
|
| 393 | +```ts |
| 394 | +import { authGuardFn, authHttpInterceptorFn, provideAuth0 } from '@auth0/auth0-angular'; |
| 395 | + |
| 396 | +const routes: Routes = [ |
| 397 | + { |
| 398 | + path: 'profile', |
| 399 | + component: ProfileComponent, |
| 400 | + canActivate: [authGuardFn], |
| 401 | + } |
| 402 | +]; |
| 403 | + |
| 404 | +bootstrapApplication(AppComponent, { |
| 405 | + providers: [ |
| 406 | + provideRouter(routes), |
| 407 | + provideAuth0(/* Auth Config Goes Here */), |
| 408 | + provideHttpClient( |
| 409 | + withInterceptors([authHttpInterceptorFn]) |
| 410 | + ) |
| 411 | + ] |
| 412 | +}); |
| 413 | +``` |
| 414 | +
|
| 415 | +Note that `provideAuth0` should **never** be provided to components, but only at the root level of your application. |
0 commit comments