Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't remove session for identity linking errors #987

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ import {
isAuthError,
isAuthRetryableFetchError,
isAuthSessionMissingError,
isAuthImplicitGrantRedirectError,
} from './lib/errors'
import {
Fetch,
@@ -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,
6 changes: 6 additions & 0 deletions src/lib/errors.ts
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion src/lib/locks.ts
Original file line number Diff line number Diff line change
@@ -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
}),
Loading