Skip to content

Commit dc988cd

Browse files
Add option to disable the focus event listener
1 parent 9bacf7e commit dc988cd

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

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)