Skip to content

Commit

Permalink
feat: _recoverAndRefresh does not remove session on retryable error
Browse files Browse the repository at this point in the history
  • Loading branch information
hf committed Jun 26, 2023
1 parent b3a6ff4 commit 252f1a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
AuthUnknownError,
isAuthApiError,
isAuthError,
isAuthRetryableFetchError,
} from './lib/errors'
import { Fetch, _request, _sessionResponse, _userResponse, _ssoResponse } from './lib/fetch'
import {
Expand Down Expand Up @@ -1274,8 +1275,11 @@ export default class GoTrueClient {
const { error } = await this._callRefreshToken(currentSession.refresh_token)

if (error) {
console.log(error.message)
await this._removeSession()
console.error(error)

if (!isAuthRetryableFetchError(error)) {
await this._removeSession()
}
}
}
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,7 @@ export class AuthRetryableFetchError extends CustomAuthError {
super(message, 'AuthRetryableFetchError', status)
}
}

export function isAuthRetryableFetchError(error: unknown): error is AuthRetryableFetchError {
return isAuthError(error) && error.name === 'AuthRetryableFetchError'
}

0 comments on commit 252f1a8

Please sign in to comment.