Skip to content

Commit

Permalink
Add autoLogoutOnTokenRefreshError config
Browse files Browse the repository at this point in the history
  • Loading branch information
DonOmalVindula committed Nov 1, 2024
1 parent b20f995 commit 39d3e58
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { SPAUtils } from "./utils";
* Default configurations.
*/
const DefaultConfig: Partial<AuthClientConfig<Config>> = {
autoLogoutOnTokenRefreshError: true,
checkSessionInterval: 3,
clientHost: origin,
enableOIDCSessionManagement: false,
Expand Down Expand Up @@ -241,12 +242,15 @@ export class AsgardeoSPAClient {
workerFile && this.instantiateWorker(workerFile);

if (!(this._storage === Storage.WebWorker)) {
const mainThreadClientConfig = config as AuthClientConfig<MainThreadClientConfig>;
const defaultConfig = { ...DefaultConfig } as Partial<AuthClientConfig<MainThreadClientConfig>>;
const mergedConfig: AuthClientConfig<MainThreadClientConfig> = {
...defaultConfig, ...mainThreadClientConfig };

if (!this._client) {
const mainThreadClientConfig = config as AuthClientConfig<MainThreadClientConfig>;
const defaultConfig = { ...DefaultConfig } as Partial<AuthClientConfig<MainThreadClientConfig>>;
this._client = await MainThreadClient(
this._instanceID,
{ ...defaultConfig, ...mainThreadClientConfig },
mergedConfig,
(
authClient: AsgardeoAuthClient<MainThreadClientConfig>,
spaHelper: SPAHelper<MainThreadClientConfig>
Expand All @@ -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();
Expand Down
1 change: 1 addition & 0 deletions lib/src/models/client-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface SPAConfig {
resourceServerURLs?: string[];
authParams?: Record<string, string>
periodicTokenRefresh?: boolean;
autoLogoutOnTokenRefreshError?: boolean;
}

/**
Expand Down

0 comments on commit 39d3e58

Please sign in to comment.