auth0 / auth0-angular

Auth0 SDK for Angular Single Page Applications
MIT License
174 stars 57 forks source link

NullInjectorError: No provider for InjectionToken auth0.client! #600

Closed byrneciaran closed 3 months ago

byrneciaran commented 3 months ago

Checklist

Description

I'm developing a simple Angular 17 SSR app using standalone components and provideAuth0. I'm getting

Here's my bootstrap code in main.ts

bootstrapApplication(AppComponent, { providers: [ provideRouter(routes), provideClientHydration(), provideHttpClient(), provideAnimations(), provideAuth0({ domain: 'XXXX, clientId: 'XXXX', authorizationParams: { redirect_uri: 'XXXX', }, }) ], }).catch(err => console.error(err));

I have a simple login button test page

import {Component} from '@angular/core'; import {RouterLink} from "@angular/router"; import {AuthService} from "@auth0/auth0-angular";

@Component({ selector: 'app-home', standalone: true, imports: [ RouterLink ], templateUrl: 'home.component.html', styles: `` }) export class HomeComponent {

constructor(private auth: AuthService) {}

handleLogin(): void {
    this.auth.loginWithRedirect({
        appState: {
            target: '/planner',
        }
    });
}

}

and here is the error

ERROR Error [NullInjectorError]: R3InjectorError(Standalone[_AppComponent])[AuthService -> AuthService -> InjectionToken auth0.client -> InjectionToken auth0.client]: NullInjectorError: No provider for InjectionToken auth0.client! at NullInjector.get (eval at instantiateModule (file:///Users/ciaranbyrne/Documents/Development%202024/Month%20Planner/month-planner/month-planner-web/node_modules/vite/dist/node/chunks/dep-68d1a114.js:56049:28), :5197:21) at R3Injector.get (eval at instantiateModule (file:///Users/ciaranbyrne/Documents/Development%202024/Month%20Planner/month-planner/month-planner-web/node_modules/vite/dist/node/chunks/dep-68d1a114.js:56049:28), :5480:27) at R3Injector.get (eval at instantiateModule (file:///Users/ciaranbyrne/Documents/Development%202024/Month%20Planner/month-planner/month-planner-web/node_modules/vite/dist/node/chunks/dep-68d1a114.js:56049:28), :5480:27) at injectInjectorOnly (eval at instantiateModule (file:///Users/ciaranbyrne/Documents/Development%202024/Month%20Planner/month-planner/month-planner-web/node_modules/vite/dist/node/chunks/dep-68d1a114.js:56049:28), :2568:36) at Module.ɵɵinject (eval at instantiateModule (file:///Users/ciaranbyrne/Documents/Development%202024/Month%20Planner/month-planner/month-planner-web/node_modules/vite/dist/node/chunks/dep-68d1a114.js:56049:28), :2574:59) at Object.AuthService_Factory [as factory] (eval at instantiateModule (file:///Users/ciaranbyrne/Documents/Development%202024/Month%20Planner/month-planner/month-planner-web/node_modules/vite/dist/node/chunks/dep-68d1a114.js:56049:28), :1503:56) at eval (eval at instantiateModule (file:///Users/ciaranbyrne/Documents/Development%202024/Month%20Planner/month-planner/month-planner-web/node_modules/vite/dist/node/chunks/dep-68d1a114.js:56049:28), :5577:33) at runInInjectorProfilerContext (eval at instantiateModule (file:///Users/ciaranbyrne/Documents/Development%202024/Month%20Planner/month-planner/month-planner-web/node_modules/vite/dist/node/chunks/dep-68d1a114.js:56049:28), :2540:5) at R3Injector.hydrate (eval at instantiateModule (file:///Users/ciaranbyrne/Documents/Development%202024/Month%20Planner/month-planner/month-planner-web/node_modules/vite/dist/node/chunks/dep-68d1a114.js:56049:28), :5576:9) at R3Injector.get (eval at instantiateModule (file:///Users/ciaranbyrne/Documents/Development%202024/Month%20Planner/month-planner/month-planner-web/node_modules/vite/dist/node/chunks/dep-68d1a114.js:56049:28), :5475:23) { ngTempTokenPath: null, ngTokenPath: [ 'AuthService', 'AuthService', 'InjectionToken auth0.client', 'InjectionToken auth0.client' ] }

Reproduction

This issue can be reproduced consistently

Additional context

No response

auth0-angular version

2.2.3

Angular version

17.0.0

Which browsers have you tested in?

Chrome