Skip to content

Commit

Permalink
fix: don't remove session for identity linking errors (#987)
Browse files Browse the repository at this point in the history
## What kind of change does this PR introduce?
* Don't remove session for identity linking errors
* Dependent on supabase/auth#1855
  • Loading branch information
kangmingtay authored Dec 4, 2024
1 parent dfb40d2 commit e68ebe6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
12 changes: 10 additions & 2 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
isAuthError,
isAuthRetryableFetchError,
isAuthSessionMissingError,
isAuthImplicitGrantRedirectError,
} from './lib/errors'
import {
Fetch,
Expand Down Expand Up @@ -314,8 +315,15 @@ export default class GoTrueClient {
if (error) {
this._debug('#_initialize()', 'error detecting session from URL', error)

if (error?.code === 'identity_already_exists') {
return { error }
if (isAuthImplicitGrantRedirectError(error)) {
const errorCode = error.details?.code
if (
errorCode === 'identity_already_exists' ||
errorCode === 'identity_not_found' ||
errorCode === 'single_identity_not_deletable'
) {
return { error }
}
}

// failed login attempt via url,
Expand Down
6 changes: 6 additions & 0 deletions src/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ export class AuthImplicitGrantRedirectError extends CustomAuthError {
}
}

export function isAuthImplicitGrantRedirectError(
error: any
): error is AuthImplicitGrantRedirectError {
return isAuthError(error) && error.name === 'AuthImplicitGrantRedirectError'
}

export class AuthPKCEGrantCodeExchangeError extends CustomAuthError {
details: { error: string; code: string } | null = null

Expand Down
2 changes: 1 addition & 1 deletion src/lib/locks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export async function processLock<R>(

const currentOperation = Promise.race(
[
previousOperation.catch((e: any) => {
previousOperation.catch(() => {
// ignore error of previous operation that we're waiting to finish
return null
}),
Expand Down

0 comments on commit e68ebe6

Please sign in to comment.