From 84b0e9943fd539e00546a8f73d8a41d07237d2f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Silke=20Gr=C3=BCber?= Date: Fri, 20 Jan 2023 09:39:38 +0100 Subject: [PATCH] fix: redirect before checkout (checkout guard) due to a cookie restore timing issue (#1357) --- src/app/core/utils/api-token/api-token.service.ts | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/app/core/utils/api-token/api-token.service.ts b/src/app/core/utils/api-token/api-token.service.ts index 3aa7b2d4c4..3d4fce9bdc 100644 --- a/src/app/core/utils/api-token/api-token.service.ts +++ b/src/app/core/utils/api-token/api-token.service.ts @@ -1,6 +1,5 @@ import { HttpErrorResponse, HttpEvent, HttpHandler, HttpParams, HttpRequest, HttpResponse } from '@angular/common/http'; import { ApplicationRef, Injectable } from '@angular/core'; -import { Router } from '@angular/router'; import { Store, select } from '@ngrx/store'; import { CookieOptions } from 'express'; import { isEqual } from 'lodash-es'; @@ -68,12 +67,7 @@ export class ApiTokenService { private initialCookie$: Observable; - constructor( - private cookiesService: CookiesService, - private router: Router, - private store: Store, - appRef: ApplicationRef - ) { + constructor(private cookiesService: CookiesService, private store: Store, appRef: ApplicationRef) { // setup initial values const initialCookie = this.parseCookie(); this.initialCookie$ = of(!SSR ? initialCookie : undefined); @@ -212,9 +206,8 @@ export class ApiTokenService { if (SSR) { return of(true); } - return this.router.events.pipe( + return this.initialCookie$.pipe( first(), - switchMap(() => this.initialCookie$), withLatestFrom(this.apiToken$), switchMap(([cookie, apiToken]) => { if (!apiToken && fetchAnonymousToken) {