Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config to prevent auto logout on token refresh errors #183

Merged
merged 1 commit into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
DonOmalVindula marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
Loading