diff --git a/src/GoTrueClient.ts b/src/GoTrueClient.ts index c8500019..127f4e8f 100644 --- a/src/GoTrueClient.ts +++ b/src/GoTrueClient.ts @@ -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 } } @@ -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 } } @@ -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 } } @@ -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 } } @@ -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 } } @@ -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 } } @@ -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 } } @@ -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 } } @@ -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() {