From c553645bb449f53165a048484e2220ef6a202b9c Mon Sep 17 00:00:00 2001 From: niculescu-bogdan-constantin Date: Mon, 8 Apr 2024 13:31:07 +0200 Subject: [PATCH] Add local storage check against parallel calls to session-service --- package-lock.json | 4 ++-- package.json | 2 +- src/identity.js | 8 ++++++++ src/version.js | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2e14ccf..a221801 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@schibsted/account-sdk-browser", - "version": "4.8.7-beta.4", + "version": "4.8.7-beta.5", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@schibsted/account-sdk-browser", - "version": "4.8.7-beta.4", + "version": "4.8.7-beta.5", "license": "MIT", "dependencies": { "tiny-emitter": "^2.1.0" diff --git a/package.json b/package.json index eaf60fe..150186c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@schibsted/account-sdk-browser", - "version": "4.8.7-beta.4", + "version": "4.8.7-beta.5", "description": "Schibsted account SDK for browsers", "main": "index.js", "type": "module", diff --git a/src/identity.js b/src/identity.js index fb1a55d..f8c6517 100644 --- a/src/identity.js +++ b/src/identity.js @@ -188,6 +188,7 @@ export class Identity extends EventEmitter { this.log = log; this.callbackBeforeRedirect = callbackBeforeRedirect; this._sessionDomain = sessionDomain; + this.cache.set("sessionFlowOngoing", false); // Internal hack: set to false to always refresh from hassession this._enableSessionCaching = true; @@ -490,6 +491,12 @@ export class Identity extends EventEmitter { * @return {Promise} */ hasSession() { + const checkIfSessionOngoing = this.cache.get("sessionFlowOngoing"); + if (checkIfSessionOngoing) + { + return this._session; + } + if (this._hasSessionInProgress) { return this._hasSessionInProgress; } @@ -533,6 +540,7 @@ export class Identity extends EventEmitter { if (sessionData){ // for expiring session and safari browser do full page redirect to gain new session if(_checkRedirectionNeed(sessionData)){ + this.cache.set("sessionFlowOngoing", true); await this.callbackBeforeRedirect(); return this._sessionService.makeUrl(sessionData.redirectURL); diff --git a/src/version.js b/src/version.js index 486704c..ccbdf3b 100644 --- a/src/version.js +++ b/src/version.js @@ -1,5 +1,5 @@ // Automatically generated in 'npm version' by scripts/genversion.js 'use strict' -const version = '4.8.7-beta.4'; +const version = '4.8.7-beta.5'; export default version;