Skip to content

Commit e68ebe6

Browse files
authored
fix: don't remove session for identity linking errors (#987)
## What kind of change does this PR introduce? * Don't remove session for identity linking errors * Dependent on supabase/auth#1855
1 parent dfb40d2 commit e68ebe6

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

src/GoTrueClient.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
isAuthError,
1313
isAuthRetryableFetchError,
1414
isAuthSessionMissingError,
15+
isAuthImplicitGrantRedirectError,
1516
} from './lib/errors'
1617
import {
1718
Fetch,
@@ -314,8 +315,15 @@ export default class GoTrueClient {
314315
if (error) {
315316
this._debug('#_initialize()', 'error detecting session from URL', error)
316317

317-
if (error?.code === 'identity_already_exists') {
318-
return { error }
318+
if (isAuthImplicitGrantRedirectError(error)) {
319+
const errorCode = error.details?.code
320+
if (
321+
errorCode === 'identity_already_exists' ||
322+
errorCode === 'identity_not_found' ||
323+
errorCode === 'single_identity_not_deletable'
324+
) {
325+
return { error }
326+
}
319327
}
320328

321329
// failed login attempt via url,

src/lib/errors.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ export class AuthImplicitGrantRedirectError extends CustomAuthError {
102102
}
103103
}
104104

105+
export function isAuthImplicitGrantRedirectError(
106+
error: any
107+
): error is AuthImplicitGrantRedirectError {
108+
return isAuthError(error) && error.name === 'AuthImplicitGrantRedirectError'
109+
}
110+
105111
export class AuthPKCEGrantCodeExchangeError extends CustomAuthError {
106112
details: { error: string; code: string } | null = null
107113

src/lib/locks.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export async function processLock<R>(
168168

169169
const currentOperation = Promise.race(
170170
[
171-
previousOperation.catch((e: any) => {
171+
previousOperation.catch(() => {
172172
// ignore error of previous operation that we're waiting to finish
173173
return null
174174
}),

0 commit comments

Comments
 (0)