Skip to content

Commit

Permalink
fix: redirect before checkout (checkout guard) due to a cookie restor…
Browse files Browse the repository at this point in the history
…e timing issue (#1357)
  • Loading branch information
SGrueber authored Jan 20, 2023
1 parent 9be2e8a commit 84b0e99
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions src/app/core/utils/api-token/api-token.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -68,12 +67,7 @@ export class ApiTokenService {

private initialCookie$: Observable<ApiTokenCookie>;

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);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 84b0e99

Please sign in to comment.