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

Redirect after sign-in breaks with query parameters #1042

Closed
CobusKruger opened this issue Apr 12, 2021 · 5 comments
Closed

Redirect after sign-in breaks with query parameters #1042

CobusKruger opened this issue Apr 12, 2021 · 5 comments
Labels

Comments

@CobusKruger
Copy link

Describe the bug
I previously had custom code to pick up the redirect entry from storage and navigate to it. When I upgraded to 11.6.4, I had to take it out, because of the navigate() call on this line:

// in check-auth.service.ts, checkAuth function:
      tap(() => {
        const savedRouteForRedirect = this.autoLoginService.getStoredRedirectRoute();
        if (savedRouteForRedirect) {
          this.autoLoginService.deleteStoredRedirectRoute(); // This removes the entry
          this.router.navigate([savedRouteForRedirect]);         // This navigates and causes the error
        }
      }),

My own navigation failed (as expected) because the redirect entry no longer exists by the time my code executed.

The new problem is that if the redirect entry contains any path with query parameters, navigation will fail. That's because navigate() doesn't support query parameters as part of the commands array. Suppose I have a URL like /?p=1, I will receive the following error:

ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'p%3D1'

Changing that line to the following should work:

          this.router.navigateByUrl(savedRouteForRedirect); // Supports query parameters

To Reproduce
Steps to reproduce the behavior:

  1. Have an app with authentication enabled.
  2. Paste a URL without query parameters into the browser address bar and press Enter. This goes through the login flow, then routes to the supplied path. Expected
  3. Paste a URL with query parameters into the browser address bar and press Enter. This goes through the login flow, then throws an error to say Cannot match any routes. Not expected

Expected behavior
Navigate to the redirect URL, whether it has query parameters or not.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrom
  • Version: 89.0.4389.114

I'll be happy to make the change.

@FabianGosebrink
Copy link
Collaborator

Hey, thanks for this. Did you try if the error is gone when you work with the QueryParamsHandling?

@CobusKruger
Copy link
Author

CobusKruger commented Apr 12, 2021 via email

@FabianGosebrink
Copy link
Collaborator

You can configure how Angular handles the queryParams. So maybe this solves the issue. You can test it and please let us know. Thanks!

@CobusKruger
Copy link
Author

@FabianGosebrink I looked into QueryParamsHandling, and I can't see how that helps in my case. Setting it to merge or preserve gets the router to pass them on, but we're going through Azure AD authentication. More than that, it's passed as a parameter to navigate(), and I don't see a way to set it globally.

@FabianGosebrink
Copy link
Collaborator

FabianGosebrink commented Apr 22, 2021

Could be related to #1028 and fixed by #1051 which is released. Please check and close if the issue is solved.

Repository owner deleted a comment from inloox-dev Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants