Skip to content

Commit 8d5e4e9

Browse files
Add option to disable the focus event listener (#36)
* Add option to disable the focus event listener * Bump version
1 parent 9bacf7e commit 8d5e4e9

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "git",
66
"url": "https://github.com/PropelAuth/javascript"
77
},
8-
"version": "2.0.20",
8+
"version": "2.0.21",
99
"keywords": [
1010
"auth",
1111
"user",

src/client.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,13 @@ export interface IAuthOptions {
184184
* Defaults to 120 seconds.
185185
*/
186186
minSecondsBeforeRefresh?: number
187+
188+
/**
189+
* If true, disables the token refresh when the tab regains focus.
190+
*
191+
* Default false
192+
*/
193+
disableRefreshOnFocus?: boolean
187194
}
188195

189196
interface AccessTokenActiveOrgMap {
@@ -603,6 +610,10 @@ export function createClient(authOptions: IAuthOptions): IAuthClient {
603610
clientState.observers = []
604611
clientState.accessTokenObservers = []
605612
window.removeEventListener("storage", onStorageChange)
613+
window.removeEventListener("online", onOnlineOrFocus)
614+
if (!authOptions.disableRefreshOnFocus) {
615+
window.removeEventListener("focus", onOnlineOrFocus)
616+
}
606617
if (clientState.refreshInterval) {
607618
clearInterval(clientState.refreshInterval)
608619
}
@@ -649,7 +660,10 @@ export function createClient(authOptions: IAuthOptions): IAuthClient {
649660
if (hasWindow()) {
650661
window.addEventListener("storage", onStorageChange)
651662
window.addEventListener("online", onOnlineOrFocus)
652-
window.addEventListener("focus", onOnlineOrFocus)
663+
664+
if (!authOptions.disableRefreshOnFocus) {
665+
window.addEventListener("focus", onOnlineOrFocus)
666+
}
653667

654668
if (authOptions.enableBackgroundTokenRefresh) {
655669
client.getAuthenticationInfoOrNull()

0 commit comments

Comments
 (0)