Skip to content

Commit af85057

Browse files
mandarinij4w8n
andauthored
fix(auth): code verifier remains in storage during edge cases (#1759)
Co-authored-by: Jason Creviston <[email protected]>
1 parent 2deb560 commit af85057

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/core/auth-js/src/GoTrueClient.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,7 @@ export default class GoTrueClient {
635635
const { data, error } = res
636636

637637
if (error || !data) {
638+
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
638639
return this._returnResult({ data: { user: null, session: null }, error: error })
639640
}
640641

@@ -648,6 +649,7 @@ export default class GoTrueClient {
648649

649650
return this._returnResult({ data: { user, session }, error: null })
650651
} catch (error) {
652+
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
651653
if (isAuthError(error)) {
652654
return this._returnResult({ data: { user: null, session: null }, error })
653655
}
@@ -1138,13 +1140,13 @@ export default class GoTrueClient {
11381140
}
11391141
return this._returnResult({ data: { ...data, redirectType: redirectType ?? null }, error })
11401142
} catch (error) {
1143+
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
11411144
if (isAuthError(error)) {
11421145
return this._returnResult({
11431146
data: { user: null, session: null, redirectType: null },
11441147
error,
11451148
})
11461149
}
1147-
11481150
throw error
11491151
}
11501152
}
@@ -1251,6 +1253,7 @@ export default class GoTrueClient {
12511253
}
12521254
throw new AuthInvalidCredentialsError('You must provide either an email or phone number.')
12531255
} catch (error) {
1256+
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
12541257
if (isAuthError(error)) {
12551258
return this._returnResult({ data: { user: null, session: null }, error })
12561259
}
@@ -1357,6 +1360,7 @@ export default class GoTrueClient {
13571360

13581361
return this._returnResult(result)
13591362
} catch (error) {
1363+
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
13601364
if (isAuthError(error)) {
13611365
return this._returnResult({ data: null, error })
13621366
}
@@ -1820,6 +1824,7 @@ export default class GoTrueClient {
18201824
return this._returnResult({ data: { user: session.user }, error: null })
18211825
})
18221826
} catch (error) {
1827+
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
18231828
if (isAuthError(error)) {
18241829
return this._returnResult({ data: { user: null }, error })
18251830
}
@@ -2272,6 +2277,7 @@ export default class GoTrueClient {
22722277
redirectTo: options.redirectTo,
22732278
})
22742279
} catch (error) {
2280+
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
22752281
if (isAuthError(error)) {
22762282
return this._returnResult({ data: null, error })
22772283
}
@@ -2401,6 +2407,7 @@ export default class GoTrueClient {
24012407
}
24022408
return this._returnResult({ data, error })
24032409
} catch (error) {
2410+
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
24042411
if (isAuthError(error)) {
24052412
return this._returnResult({ data: { user: null, session: null }, error })
24062413
}
@@ -2749,7 +2756,7 @@ export default class GoTrueClient {
27492756
// _saveSession is always called whenever a new session has been acquired
27502757
// so we can safely suppress the warning returned by future getSession calls
27512758
this.suppressGetSessionWarning = true
2752-
2759+
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
27532760
// Create a shallow copy to work with, to avoid mutating the original session object if it's used elsewhere
27542761
const sessionToProcess = { ...session }
27552762

0 commit comments

Comments
 (0)