@@ -5,7 +5,7 @@ import { currentTimeSeconds, getLocalStorageNumber, hasLocalStorage, hasWindow }
5
5
const LOGGED_IN_AT_KEY = "__PROPEL_AUTH_LOGGED_IN_AT"
6
6
const LOGGED_OUT_AT_KEY = "__PROPEL_AUTH_LOGGED_OUT_AT"
7
7
const 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
9
9
const ACTIVE_ORG_ACCESS_TOKEN_REFRESH_EXPIRATION_SECONDS = 60 * 5
10
10
11
11
const encodeBase64 = ( str : string ) => {
@@ -178,6 +178,12 @@ export interface IAuthOptions {
178
178
* Default true
179
179
*/
180
180
enableBackgroundTokenRefresh ?: boolean
181
+
182
+ /**
183
+ * Minimum number of seconds before refreshing the token again.
184
+ * Defaults to 120 seconds.
185
+ */
186
+ minSecondsBeforeRefresh ?: number
181
187
}
182
188
183
189
interface AccessTokenActiveOrgMap {
@@ -216,6 +222,8 @@ function validateAndCleanupOptions(authOptions: IAuthOptions) {
216
222
}
217
223
218
224
export function createClient ( authOptions : IAuthOptions ) : IAuthClient {
225
+ const { minSecondsBeforeRefresh = DEFAULT_MIN_SECONDS_BEFORE_REFRESH } = authOptions
226
+
219
227
validateAndCleanupOptions ( authOptions )
220
228
221
229
// Internal state
@@ -631,10 +639,7 @@ export function createClient(authOptions: IAuthOptions): IAuthClient {
631
639
// If we were offline or on a different tab, when we return, refetch auth info
632
640
// Some browsers trigger focus more often than we'd like, so we'll debounce a little here as well
633
641
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 ) {
638
643
await forceRefreshToken ( true )
639
644
} else {
640
645
await client . getAuthenticationInfoOrNull ( )
0 commit comments