Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion EXAMPLES.md
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ bootstrapApplication(AppComponent, {
});
```

Note that `provideAuth0` should **never** be provided to components, but only at the root level of your application.
**Important:** `provideAuth0` returns `EnvironmentProviders`, which ensures it can only be used at the application/environment level. Attempting to add it to a component's `providers` array will result in a compile-time error.

## Connect Accounts for using Token Vault

Expand Down
12 changes: 7 additions & 5 deletions projects/auth0-angular/src/lib/provide.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Provider } from '@angular/core';
import { EnvironmentProviders, makeEnvironmentProviders } from '@angular/core';
import { Auth0ClientService, Auth0ClientFactory } from './auth.client';
import { AuthConfig, AuthConfigService, AuthClientConfig } from './auth.config';
import { AuthGuard } from './auth.guard';
Expand All @@ -9,7 +9,9 @@ import { AuthService } from './auth.service';
* Initialize the authentication system. Configuration can either be specified here,
* or by calling AuthClientConfig.set (perhaps from an APP_INITIALIZER factory function).
*
* Note: Should only be used as of Angular 15, and should not be added to a component's providers.
* Note: Should only be used as of Angular 15. This function returns `EnvironmentProviders`
* which ensures it can only be used at the application/environment level and cannot be
* added to a component's providers array (this will result in a compile-time error).
*
* @param config The optional configuration for the SDK.
*
Expand All @@ -20,8 +22,8 @@ import { AuthService } from './auth.service';
* ],
* });
*/
export function provideAuth0(config?: AuthConfig): Provider[] {
return [
export function provideAuth0(config?: AuthConfig): EnvironmentProviders {
return makeEnvironmentProviders([
AuthService,
AuthHttpInterceptor,
AuthGuard,
Expand All @@ -34,5 +36,5 @@ export function provideAuth0(config?: AuthConfig): Provider[] {
useFactory: Auth0ClientFactory.createClient,
deps: [AuthClientConfig],
},
];
]);
}