From bf503af791fde19fd63a0158ca43576348334162 Mon Sep 17 00:00:00 2001 From: Jason Creviston Date: Thu, 29 Jun 2023 07:22:52 -0400 Subject: [PATCH] fix: remove unneeded checks and tidy up --- src/GoTrueClient.ts | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/src/GoTrueClient.ts b/src/GoTrueClient.ts index 113d8c935..37cf7d741 100644 --- a/src/GoTrueClient.ts +++ b/src/GoTrueClient.ts @@ -1352,35 +1352,28 @@ export default class GoTrueClient { } const timeNow = Math.round(Date.now() / 1000) - const expiresWithMargin = (currentSession.expires_at ?? Infinity) < timeNow + EXPIRY_MARGIN + const expiresWithMargin = currentSession.expires_at! < timeNow + EXPIRY_MARGIN this._debug( debugName, `session has${expiresWithMargin ? '' : ' not'} expired with margin of ${EXPIRY_MARGIN}s` ) - if (expiresWithMargin) { - if (this.autoRefreshToken && currentSession.refresh_token) { - const { error } = await this._callRefreshToken(currentSession.refresh_token) - - if (error) { - console.error(error) - - if (!isAuthRetryableFetchError(error)) { - this._debug( - debugName, - 'refresh failed with a non-retryable error, removing the session', - error - ) - await this._removeSession() - } + if (this.autoRefreshToken && expiresWithMargin) { + const { error } = await this._callRefreshToken(currentSession.refresh_token) + + if (error) { + console.error(error) + + if (!isAuthRetryableFetchError(error)) { + this._debug( + debugName, + 'refresh failed with a non-retryable error, removing the session', + error + ) + await this._removeSession() } } - } else { - // no need to persist currentSession again, as we just loaded it from - // local storage; persisting it again may overwrite a value saved by - // another client with access to the same local storage - await this._notifyAllSubscribers('SIGNED_IN', currentSession) } } catch (err) { this._debug(debugName, 'error', err)