Skip to content

Commit

Permalink
fix: Type error on code exchange when no item in storage (#825)
Browse files Browse the repository at this point in the history
## What kind of change does this PR introduce?

Currently when code exchange for pkce flow is triggered on device that
didn't start the auth flow (e.g. signed up via magic link on laptop and
clicked on the link on phone), `TypeError: Cannot read properties of
null (reading 'split')` error is thrown. This PR fixes that.

Fixes the error pointed out here
#813 (comment)
  • Loading branch information
dshukertjr committed Dec 17, 2023
1 parent f30daeb commit 6d6ec13
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,8 @@ export default class GoTrueClient {
}
| { data: { session: null; user: null; redirectType: null }; error: AuthError }
> {
const [codeVerifier, redirectType] = (
(await getItemAsync(this.storage, `${this.storageKey}-code-verifier`)) as string
).split('/')
const storageItem = await getItemAsync(this.storage, `${this.storageKey}-code-verifier`)
const [codeVerifier, redirectType] = ((storageItem ?? '') as string).split('/')
const { data, error } = await _request(
this.fetch,
'POST',
Expand Down

0 comments on commit 6d6ec13

Please sign in to comment.