loginWithRedirect doesn't work with target URL

Hi there,
I’m using "@auth0/auth0-angular": "^1.9.0" in my Angular project.
My issue is that loginWithRedirect is not working. I’ve this code in the LoginButtonComponent:

  loginWithRedirect(): void {
    this.auth.loginWithRedirect({
      appState: {
        target: `${window.location.pathname}/#/app/dashboard`
        // target: '#/app/dashboard'
      }
    });
  }

If I run the loginWithRedirect (of the LoginButtonComponent) from the ‘/’ root route, it does redirect to the Auth0 Universal Login, and then login with my email and password does redirect to the same ‘/’ root route, even when I put ‘app/dashboard’ as the target in my code and on Allowed Callback URLs field.

Update:

Using the property redirect_uri the code works:

loginWithRedirect(): void {
    this.auth.loginWithRedirect({
      redirect_uri: `${window.location.origin}/#/app/dashboard`,
      appState: { /* this property is useless */ }
    });
  }

Another issue is that AuthService doesn’t work. In my ‘/’ root component (LandingComponent), at the topbar I’ve this code:

            <div class="some-top-menu-items-classes">
                <div *ngIf="(auth.isAuthenticated$ | async) === false" >
                    <app-login-button></app-login-button>
                    <app-signup-button></app-signup-button>
                </div>
                <div *ngIf="auth.user$ | async as user"> <!-- -->
                    <button pButton pRipple label="Dashboard" icon="pi pi-compass" (click)="router.navigate(['/app/dashboard'])"></button>
                    <p-chip label="{{ user.name }}" image="user.picture"></p-chip>
                    <app-logout-button></app-logout-button>
                </div>
            </div>

After been redirect to ‘/’ callback URL, the login process is ok, but it always shows the Login and Signup buttons, even though the user has already been authenticated, instead of showing the user info and the Dashboard and Logout buttons.
I think this occurs because the auth is lost when refresh the page. I’m using UN/password, not Social logging.
I’m using this:

"useRefreshTokens": true,
"cacheLocation": "localstorage"

I dunno how to resolve this.

Ps: I read this and this other post where they have similar problems with the redirect callback.

1 Like

Did you figure out what to do? I am facing the same issue.