Skip to content

fix: code verifier remains in storage during edge cases #986

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
9 changes: 9 additions & 0 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,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 @@ -499,6 +500,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 @@ -639,6 +641,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 @@ -747,6 +750,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 @@ -846,6 +850,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 @@ -1289,6 +1294,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 @@ -1719,6 +1725,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 @@ -1780,6 +1787,7 @@ export default class GoTrueClient {
}
return { data: { provider: credentials.provider, url: data?.url }, error: null }
} catch (error) {
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
if (isAuthError(error)) {
return { data: { provider: credentials.provider, url: null }, error }
}
Expand Down Expand Up @@ -2065,6 +2073,7 @@ export default class GoTrueClient {
// so we can safely suppress the warning returned by future getSession calls
this.suppressGetSessionWarning = true
await setItemAsync(this.storage, this.storageKey, session)
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
}

private async _removeSession() {
Expand Down