Skip to content

Commit

Permalink
Add local storage check against parallel calls to session-service
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan-niculescu-sch committed Apr 8, 2024
1 parent b17a705 commit c553645
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
8 changes: 8 additions & 0 deletions src/identity.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -490,6 +491,12 @@ export class Identity extends EventEmitter {
* @return {Promise<HasSessionSuccessResponse|HasSessionFailureResponse>}
*/
hasSession() {
const checkIfSessionOngoing = this.cache.get("sessionFlowOngoing");
if (checkIfSessionOngoing)
{
return this._session;
}

if (this._hasSessionInProgress) {
return this._hasSessionInProgress;
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/version.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit c553645

Please sign in to comment.