Handle appState and redirect to dynamic url after successful login(Auth0 Angular)

In the Auth0 Spa JS, I could execute the auth0.handleRedirectCallback() function to return the appState from the auth0.loginWithRedirect({appState}) when it is passed in. This used to allow me to redirect to any url I wanted after a successful login or successfully completing an auth guard, into my application.

In the new auth0/angular library the auth0.handleRedirectCallback() is now private and can’t be used outside the class. Therefore, how is appState returned and used in the new implementation?

Thanks, Kav

4 Likes

I have the same problem. Any news ?

@kav.khalsa, @rlopez
I just submitted a PR that adds an appState$ observable to the AuthService class: https://github.com/auth0/auth0-angular/pull/168

If/when this PR gets merged, you can subscribe to this observable to receive the appState after the user gets redirected back to your application:

import { Component, OnInit } from '@angular/core';
import { AuthService } from '@auth0/auth0-angular';

@Component({
  selector: '...',
  templateUrl: '...',
  styleUrls: ['....'],
})
export class AppComponent implements OnInit {
  constructor(public auth: AuthService) {}

  ngOnInit() {
    this.auth.appState$.subscribe((appState) => {
      console.log(appState);
    });
  }
}
1 Like

Thanks for doing that and sharing with the rest of community!