@@ -5,7 +5,7 @@ import { currentTimeSeconds, getLocalStorageNumber, hasLocalStorage, hasWindow }
55const LOGGED_IN_AT_KEY = "__PROPEL_AUTH_LOGGED_IN_AT"
66const LOGGED_OUT_AT_KEY = "__PROPEL_AUTH_LOGGED_OUT_AT"
77const AUTH_TOKEN_REFRESH_BEFORE_EXPIRATION_SECONDS = 10 * 60
8- const DEBOUNCE_DURATION_FOR_REFOCUS_SECONDS = 60
8+ const DEFAULT_MIN_SECONDS_BEFORE_REFRESH = 60 * 2
99const ACTIVE_ORG_ACCESS_TOKEN_REFRESH_EXPIRATION_SECONDS = 60 * 5
1010
1111const encodeBase64 = ( str : string ) => {
@@ -178,6 +178,12 @@ export interface IAuthOptions {
178178 * Default true
179179 */
180180 enableBackgroundTokenRefresh ?: boolean
181+
182+ /**
183+ * Minimum number of seconds before refreshing the token again.
184+ * Defaults to 120 seconds.
185+ */
186+ minSecondsBeforeRefresh ?: number
181187}
182188
183189interface AccessTokenActiveOrgMap {
@@ -216,6 +222,8 @@ function validateAndCleanupOptions(authOptions: IAuthOptions) {
216222}
217223
218224export function createClient ( authOptions : IAuthOptions ) : IAuthClient {
225+ const { minSecondsBeforeRefresh = DEFAULT_MIN_SECONDS_BEFORE_REFRESH } = authOptions
226+
219227 validateAndCleanupOptions ( authOptions )
220228
221229 // Internal state
@@ -631,10 +639,7 @@ export function createClient(authOptions: IAuthOptions): IAuthClient {
631639 // If we were offline or on a different tab, when we return, refetch auth info
632640 // Some browsers trigger focus more often than we'd like, so we'll debounce a little here as well
633641 const onOnlineOrFocus = async function ( ) {
634- if (
635- clientState . lastRefresh &&
636- currentTimeSeconds ( ) > clientState . lastRefresh + DEBOUNCE_DURATION_FOR_REFOCUS_SECONDS
637- ) {
642+ if ( clientState . lastRefresh && currentTimeSeconds ( ) > clientState . lastRefresh + minSecondsBeforeRefresh ) {
638643 await forceRefreshToken ( true )
639644 } else {
640645 await client . getAuthenticationInfoOrNull ( )
0 commit comments