Angular Auth0 "Invalid State" issue

Viewed 308

I am trying to add Auth0 to my angular app (I use .NET Core Angular project template in VS2022).

  • .NET 6
  • Angular: 13.0.2
  • @auth0/auth0-angular: 1.8.0

First, I followed https://auth0.com/docs/quickstart/spa/angular/01-login, but after login Auth0 redirects me back to my site (localhost) with "code" and "state" query parameters. I found handleRedirectCallback() method and call it. But I get an error: enter image description here

Auth0 code is small enough:

AuthModule.forRoot({
  domain: environment.auth0.domain,
  clientId: environment.auth0.clientId,
  redirectUri: environment.auth0.redirectUrl
})

export class LoginComponent {
  constructor(auth: AuthService) {
    if (window.location.href.indexOf('state=') > -1) {
      auth.handleRedirectCallback().subscribe(value => {
        debugger;
      });
    } else {
      auth.loginWithRedirect();
    }
  }
}

I also created a new default angular project and added the code, but I still see the Invalid state error.

1 Answers

I shouldn't need to explicitly call handleRedirectCallback, the library does that automatically.

Related