Skip to content

Commit 36cfef1

Browse files
Add example for Standalone components and a more functional approach (#443)
Co-authored-by: Steve Hobbs <[email protected]>
1 parent 404b951 commit 36cfef1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

EXAMPLES.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- [Call an API](#call-an-api)
99
- [Handling errors](#handling-errors)
1010
- [Organizations](#organizations)
11+
- [Standalone Components and a more functional approach](#standalone-components-and-a-more-functional-approach)
1112

1213
## Add login to your application
1314

@@ -378,3 +379,37 @@ export class AppComponent {
378379
}
379380
}
380381
```
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

Comments
 (0)