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", 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()