Skip to content

Commit

Permalink
fix: don't throw error in exchangeCodeForSession
Browse files Browse the repository at this point in the history
  • Loading branch information
kangmingtay committed Aug 26, 2024
1 parent 274c94a commit d23f813
Showing 1 changed file with 34 additions and 24 deletions.
58 changes: 34 additions & 24 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,33 +580,43 @@ export default class GoTrueClient {
> {
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',
`${this.url}/token?grant_type=pkce`,
{
headers: this.headers,
body: {
auth_code: authCode,
code_verifier: codeVerifier,
},
xform: _sessionResponse,

try {
const { data, error } = await _request(
this.fetch,
'POST',
`${this.url}/token?grant_type=pkce`,
{
headers: this.headers,
body: {
auth_code: authCode,
code_verifier: codeVerifier,
},
xform: _sessionResponse,
}
)
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
if (error) {
throw error
}
)
await removeItemAsync(this.storage, `${this.storageKey}-code-verifier`)
if (error) {
return { data: { user: null, session: null, redirectType: null }, error }
} else if (!data || !data.session || !data.user) {
return {
data: { user: null, session: null, redirectType: null },
error: new AuthInvalidTokenResponseError(),
if (!data || !data.session || !data.user) {
return {
data: { user: null, session: null, redirectType: null },
error: new AuthInvalidTokenResponseError(),
}
}
if (data.session) {
await this._saveSession(data.session)
await this._notifyAllSubscribers('SIGNED_IN', data.session)
}
return { data: { ...data, redirectType: redirectType ?? null }, error }
} catch (error) {
if (isAuthError(error)) {
return { data: { user: null, session: null, redirectType: null }, error }
}

throw error
}
if (data.session) {
await this._saveSession(data.session)
await this._notifyAllSubscribers('SIGNED_IN', data.session)
}
return { data: { ...data, redirectType: redirectType ?? null }, error }
}

/**
Expand Down

0 comments on commit d23f813

Please sign in to comment.