From dc988cd45713a85c3bbd11c45203de38143b874b Mon Sep 17 00:00:00 2001 From: Andrew Israel Date: Tue, 11 Mar 2025 13:03:07 -0700 Subject: [PATCH 1/2] Add option to disable the focus event listener --- src/client.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/client.ts b/src/client.ts index e44f21c..a14f8c5 100644 --- a/src/client.ts +++ b/src/client.ts @@ -184,6 +184,13 @@ export interface IAuthOptions { * Defaults to 120 seconds. */ minSecondsBeforeRefresh?: number + + /** + * If true, disables the token refresh when the tab regains focus. + * + * Default false + */ + disableRefreshOnFocus?: boolean } interface AccessTokenActiveOrgMap { @@ -603,6 +610,10 @@ export function createClient(authOptions: IAuthOptions): IAuthClient { clientState.observers = [] clientState.accessTokenObservers = [] window.removeEventListener("storage", onStorageChange) + window.removeEventListener("online", onOnlineOrFocus) + if (!authOptions.disableRefreshOnFocus) { + window.removeEventListener("focus", onOnlineOrFocus) + } if (clientState.refreshInterval) { clearInterval(clientState.refreshInterval) } @@ -649,7 +660,10 @@ export function createClient(authOptions: IAuthOptions): IAuthClient { if (hasWindow()) { window.addEventListener("storage", onStorageChange) window.addEventListener("online", onOnlineOrFocus) - window.addEventListener("focus", onOnlineOrFocus) + + if (!authOptions.disableRefreshOnFocus) { + window.addEventListener("focus", onOnlineOrFocus) + } if (authOptions.enableBackgroundTokenRefresh) { client.getAuthenticationInfoOrNull() From 26e33c5b9519fdbfecd5fce8333ae8389909dcb9 Mon Sep 17 00:00:00 2001 From: Andrew Israel Date: Tue, 11 Mar 2025 13:03:29 -0700 Subject: [PATCH 2/2] Bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 77c023a..248b025 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "type": "git", "url": "https://github.com/PropelAuth/javascript" }, - "version": "2.0.20", + "version": "2.0.21", "keywords": [ "auth", "user",