Skip to content

Commit

Permalink
Fix/double redirect issue (#1924)
Browse files Browse the repository at this point in the history
* double-redirect-issue

* protect double redirect

* Take one

* remove logs

* remove logs

* Remove test data

* fix logic

* 🤖 GITHUB ACTIONS

* Revert ublock fix

* Rever unrequired changes

* Add logs

* 🤖 GITHUB ACTIONS

* Final fix
  • Loading branch information
leomendoza123 authored Mar 31, 2023
1 parent c361894 commit 6c26919
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/app/guards/authorize.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
RouterStateSnapshot,
UrlTree,
} from '@angular/router'
import { forkJoin, NEVER, Observable, of, throwError } from 'rxjs'
import { forkJoin, NEVER, Observable, of, throwError, timer } from 'rxjs'
import { catchError, map, switchMap, take, tap, timeout } from 'rxjs/operators'

import { PlatformInfoService } from '../cdk/platform-info'
Expand Down Expand Up @@ -67,13 +67,7 @@ export class AuthorizeGuard implements CanActivateChild {
}

sendUserToRedirectURL(oauthSession: RequestInfoForm): Observable<boolean> {
console.log('sendUserToRedirectURL ', oauthSession)

// if (this.lastRedirectUrl !== oauthSession.redirectUrl) {
// this.lastRedirectUrl = oauthSession.redirectUrl
this.window.location.href = oauthSession.redirectUrl
// }

return NEVER
}

Expand Down Expand Up @@ -104,9 +98,11 @@ export class AuthorizeGuard implements CanActivateChild {
)
return this.sendUserToRedirectURL(request)
}),
switchMap(() => {
return NEVER
})
// If and Add blocker like Ublock is enable the GTM `redirectURL` will never be called
// This add blockers will also not trigger the `catchError` above, since GTM will not throw an error
// So this timeout will redirect the user to the redirectURL after 4 seconds of waiting for the GTM redirect
switchMap(() => timer(4000)),
switchMap(() => this.sendUserToRedirectURL(request))
)
}

Expand Down

0 comments on commit 6c26919

Please sign in to comment.