From 39d3e581f03706e519ef89a2b84207c78fcf0bd4 Mon Sep 17 00:00:00 2001 From: DonOmalVindula Date: Fri, 1 Nov 2024 19:21:59 +0530 Subject: [PATCH] Add autoLogoutOnTokenRefreshError config --- lib/src/client.ts | 17 +++++++++++++---- lib/src/models/client-config.ts | 1 + 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/src/client.ts b/lib/src/client.ts index bf3ad019..6386f041 100755 --- a/lib/src/client.ts +++ b/lib/src/client.ts @@ -51,6 +51,7 @@ import { SPAUtils } from "./utils"; * Default configurations. */ const DefaultConfig: Partial> = { + autoLogoutOnTokenRefreshError: true, checkSessionInterval: 3, clientHost: origin, enableOIDCSessionManagement: false, @@ -241,12 +242,15 @@ export class AsgardeoSPAClient { workerFile && this.instantiateWorker(workerFile); if (!(this._storage === Storage.WebWorker)) { + const mainThreadClientConfig = config as AuthClientConfig; + const defaultConfig = { ...DefaultConfig } as Partial>; + const mergedConfig: AuthClientConfig = { + ...defaultConfig, ...mainThreadClientConfig }; + if (!this._client) { - const mainThreadClientConfig = config as AuthClientConfig; - const defaultConfig = { ...DefaultConfig } as Partial>; this._client = await MainThreadClient( this._instanceID, - { ...defaultConfig, ...mainThreadClientConfig }, + mergedConfig, ( authClient: AsgardeoAuthClient, spaHelper: SPAHelper @@ -261,7 +265,12 @@ export class AsgardeoSPAClient { if (this._onInitialize) { this._onInitialize(true); } - + + // Do not sign out the user if the autoLogoutOnTokenRefreshError is set to false. + if (!mergedConfig.autoLogoutOnTokenRefreshError) { + return Promise.resolve(true); + } + window.addEventListener("message", (event) => { if (event?.data?.type === REFRESH_ACCESS_TOKEN_ERR0R) { this.signOut(); diff --git a/lib/src/models/client-config.ts b/lib/src/models/client-config.ts index 2047e373..a6da3607 100644 --- a/lib/src/models/client-config.ts +++ b/lib/src/models/client-config.ts @@ -32,6 +32,7 @@ export interface SPAConfig { resourceServerURLs?: string[]; authParams?: Record periodicTokenRefresh?: boolean; + autoLogoutOnTokenRefreshError?: boolean; } /**