Skip to content

Observable returned by AuthGuard does not wait until auth.loginWithRedirect finishes #659

@Mobe91

Description

@Mobe91

Checklist

Description

The current implementation of the AuthGuard returns an Observable from canActivate that is produced like this:

  private redirectIfUnauthenticated(
    state: RouterStateSnapshot
  ): Observable<boolean> {
    return this.auth.isAuthenticated$.pipe(
      tap((loggedIn) => {
        if (!loggedIn) {
          this.auth.loginWithRedirect({
            appState: { target: state.url },
          });
        }
      })
    );
  }

The logic of this is that auth.loginWithRedirect will perform a redirect for login when the user is not logged in. However, auth.loginWithRedirect also returns an Observable which is ignored by this implementation. This means that the consumer of the guard will not wait for auth.loginWithRedirect to complete.

Reproduction

I did not try to reproduce effects of this issue.

Additional context

No response

auth0-angular version

2.2.3

Angular version

13

Which browsers have you tested in?

Chrome

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis points to a verified bug in the code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions