From ccedf02bb12e2e2d4fd9e2ced7973ab5c440de5a Mon Sep 17 00:00:00 2001 From: leomendoza123 Date: Sat, 8 Apr 2023 11:21:38 -0600 Subject: [PATCH] 1926 (#1928) * 1926 * add comments --- src/app/guards/authorize.guard.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/app/guards/authorize.guard.ts b/src/app/guards/authorize.guard.ts index 83feb793ba..4bca7c0e7d 100644 --- a/src/app/guards/authorize.guard.ts +++ b/src/app/guards/authorize.guard.ts @@ -23,6 +23,7 @@ import { GoogleTagManagerService } from '../core/google-tag-manager/google-tag-m }) export class AuthorizeGuard implements CanActivateChild { lastRedirectUrl: string + redirectTroughGtmWasCalled: boolean constructor( private _user: UserService, private _router: Router, @@ -72,8 +73,6 @@ export class AuthorizeGuard implements CanActivateChild { } reportAlreadyAuthorize(request: RequestInfoForm) { - console.log('reportAlreadyAuthorize') - const analyticsReports: Observable[] = [] analyticsReports.push( this._gtag.reportEvent(`Reauthorize`, 'RegGrowth', request) @@ -81,6 +80,11 @@ export class AuthorizeGuard implements CanActivateChild { analyticsReports.push( this._googleTagManagerService.reportEvent(`Reauthorize`, request) ) + addEventListener('beforeunload', (event) => { + // temporally keeping the console logs to debug the issue + console.log('beforeunload', event) + this.redirectTroughGtmWasCalled = true + }) return forkJoin(analyticsReports).pipe( tap( @@ -102,7 +106,14 @@ export class AuthorizeGuard implements CanActivateChild { // 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)) + switchMap(() => { + // Checks that a redirect by GTM is not already in progress + // Stop a second redirect to happen if the a browser event `beforeunload` event was triggered + if (this.redirectTroughGtmWasCalled) { + return NEVER + } + return this.sendUserToRedirectURL(request) + }) ) }