Skip to content
Open
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
10 changes: 9 additions & 1 deletion packages/core/auth-js/src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ export default class GoTrueClient {
const { data, error } = res

if (error || !data) {
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
return { data: { user: null, session: null }, error: error }
}

Expand All @@ -585,6 +586,7 @@ export default class GoTrueClient {

return { data: { user, session }, error: null }
} catch (error) {
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
if (isAuthError(error)) {
return { data: { user: null, session: null }, error }
}
Expand Down Expand Up @@ -1078,6 +1080,7 @@ export default class GoTrueClient {
return { data: { ...data, redirectType: redirectType ?? null }, error }
} catch (error) {
if (isAuthError(error)) {
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
return { data: { user: null, session: null, redirectType: null }, error }
}

Expand Down Expand Up @@ -1186,6 +1189,7 @@ export default class GoTrueClient {
}
throw new AuthInvalidCredentialsError('You must provide either an email or phone number.')
} catch (error) {
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
if (isAuthError(error)) {
return { data: { user: null, session: null }, error }
}
Expand Down Expand Up @@ -1285,6 +1289,7 @@ export default class GoTrueClient {
xform: _ssoResponse,
})
} catch (error) {
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
if (isAuthError(error)) {
return { data: null, error }
}
Expand Down Expand Up @@ -1741,6 +1746,7 @@ export default class GoTrueClient {
return { data: { user: session.user }, error: null }
})
} catch (error) {
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
if (isAuthError(error)) {
return { data: { user: null }, error }
}
Expand Down Expand Up @@ -2193,6 +2199,7 @@ export default class GoTrueClient {
redirectTo: options.redirectTo,
})
} catch (error) {
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
if (isAuthError(error)) {
return { data: null, error }
}
Expand Down Expand Up @@ -2319,6 +2326,7 @@ export default class GoTrueClient {
}
return { data, error }
} catch (error) {
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
if (isAuthError(error)) {
return { data: { user: null, session: null }, error }
}
Expand Down Expand Up @@ -2667,7 +2675,7 @@ export default class GoTrueClient {
// _saveSession is always called whenever a new session has been acquired
// so we can safely suppress the warning returned by future getSession calls
this.suppressGetSessionWarning = true

await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
// Create a shallow copy to work with, to avoid mutating the original session object if it's used elsewhere
const sessionToProcess = { ...session }

Expand Down