Skip to content

feat(redirectUnauthorizedTo): allow passing query parameters #2287

Closed

Description

@AmitMY

Version info

Angular:
~9.0.0-rc.7

Firebase:
^7.6.1-0

AngularFire:
^5.3.0-rc.4

Using the AngularFireAuthGuard works, but does not support redirect with query parameters.
When a user isn't authenticated, I'd like to direct them to login, and once they are logged in send them back to where they tried to access.

const redirectUnauthorizedToLogin = (route: ActivatedRouteSnapshot) => {
  const path = route.pathFromRoot.map(v => v.url.map(segment => segment.toString()).join('/')).join('/');
  const params = String(new URLSearchParams(route.queryParams));

  // const url = '/?' + String(new URLSearchParams({redirect: path + '?' + params}));

  return redirectUnauthorizedTo(['/']);
};

But I can't redirect to this url as its not a valid segment, and redirectUnauthorizedTo doesn't support query parameters

Activity

  1. jamesdaniels commented on Feb 6, 2020

    @jamesdaniels
    Contributor

    Would allowing you to return your own UrlTree be sufficient?

  2. AmitMY commented on Feb 9, 2020

    @AmitMY
    Author

    I believe it would be, yes.

    For now, instead of using urls, i'm using:

    const redirectUnauthorizedToLogin = (route: ActivatedRouteSnapshot) => {
      const path = route.pathFromRoot.map(v => v.url.map(segment => segment.toString()).join('/')).join('/');
      const params = route.queryParams;
    
      return pipe(
        loggedIn,
        tap((isLoggedIn) => {
          if (!isLoggedIn) {
            console.log('Saving afterLogin');
            sessionStorage.setItem('afterLogin', JSON.stringify({path, params}));
          }
        }),
        map(loggedIn => loggedIn || ['/'])
      );
    };
  3. EdricChan03 commented on May 9, 2020

    @EdricChan03
    Contributor

    Isn't this issue a duplicate of #2144?

    Anyways, I'm currently attempting to introduce a fix for this issue by allowing the consumer to specify a UrlTree to the pipes.

  4. added 3 commits that reference this issue on May 9, 2020
    41cf36d
    867478f
    e5cb663
  5. added a commit that references this issue on May 23, 2020
    cd67dd3
  6. added a commit that references this issue on Jun 15, 2020
    9eeba6c
  7. n0mer commented on Jul 9, 2020

    @n0mer

    @EdricChan03 any luck :) ?

  8. added a commit that references this issue on Nov 11, 2020
    fe31191
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions