Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorporate observable of loginWithRedirect in observable returned by AuthGuard #660

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Mobe91
Copy link

@Mobe91 Mobe91 commented Nov 19, 2024

… AuthGuard (#659)

By submitting a PR to this repository, you agree to the terms within the Auth0 Code of Conduct. Please see the contributing guidelines for how to create and submit a high-quality PR for this repo.

Description

See #659

References

#659

Testing

Describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.

Please include any manual steps for testing end-to-end or functionality not covered by unit/integration tests.

Also include details of the environment this PR was developed in (language/platform/browser version).

  • This change adds test coverage for new/changed/fixed functionality

Checklist

  • [ x] I have added documentation for new/changed functionality in this PR or in auth0.com/docs
  • All active GitHub checks for tests, formatting, and security are passing
  • [ x] The correct base branch is being used, if not the default branch

@Mobe91 Mobe91 requested a review from a team as a code owner November 19, 2024 11:30
@frederikprijck frederikprijck changed the title Incorporate observable of loginWithRedirect in observable returned by… Incorporate observable of loginWithRedirect in observable returned by AuthGuard Nov 20, 2024
@tusharpandey13
Copy link
Contributor

Hi @Mobe91,
in the case loginWithRedirect fails, shouldn't there be a check to handle the failure case as well, instead of always returning true?
Maybe this snippet can help:

return this.auth.isAuthenticated$.pipe(
    switchMap((loggedIn) => {
      if (!loggedIn) {
        return this.auth.loginWithRedirect({
          appState: { target: state.url },
        }).pipe(
          map(() => false),
          catchError(() => of(false))
        );
      }
      return of(true);
    })
  );

@Mobe91
Copy link
Author

Mobe91 commented Dec 9, 2024

@tusharpandey13
I think this would just swallow the error and would make it impossible for the caller to maybe act differently on an error. In this case, Angular is the caller that invokes canActivate. Catching an error and returning false in that case prevents Angular from potentially doing more stuff with the error (e.g. logging it).

@Mobe91
Copy link
Author

Mobe91 commented Dec 23, 2024

@tusharpandey13 Do you have any more feedback on this change? Do you think we could merge this?

@tusharpandey13
Copy link
Contributor

tusharpandey13 commented Dec 23, 2024

@Mobe91, this LGTM 👍
In order to merge this, we need signed commits, please see this doc
Please sign your commit and update your branch and we can merge this.
Thanks.

@tusharpandey13
Copy link
Contributor

Please note that we have some broken CI checks which are currently failing, they should not block merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants