Skip to content

Commit

Permalink
fix: return error early for redirects
Browse files Browse the repository at this point in the history
  • Loading branch information
kangmingtay committed Dec 12, 2024
1 parent 2e6e07c commit ab7630f
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1422,15 +1422,24 @@ export default class GoTrueClient {
| { data: { session: null; redirectType: null }; error: AuthError }
> {
try {
const params = parseParametersFromURL(window.location.href)
if (params.error || params.error_description || params.error_code) {
throw new AuthImplicitGrantRedirectError(
params.error_description || 'Error in URL with unspecified error_description',
{
error: params.error || 'unspecified_error',
code: params.error_code || 'unspecified_code',
}
)
}

if (!isBrowser()) throw new AuthImplicitGrantRedirectError('No browser detected.')
if (this.flowType === 'implicit' && !this._isImplicitGrantFlow()) {
throw new AuthImplicitGrantRedirectError('Not a valid implicit grant flow url.')
} else if (this.flowType == 'pkce' && !isPKCEFlow) {
throw new AuthPKCEGrantCodeExchangeError('Not a valid PKCE flow url.')
}

const params = parseParametersFromURL(window.location.href)

if (isPKCEFlow) {
if (!params.code) throw new AuthPKCEGrantCodeExchangeError('No code detected.')
const { data, error } = await this._exchangeCodeForSession(params.code)
Expand All @@ -1444,16 +1453,6 @@ export default class GoTrueClient {
return { data: { session: data.session, redirectType: null }, error: null }
}

if (params.error || params.error_description || params.error_code) {
throw new AuthImplicitGrantRedirectError(
params.error_description || 'Error in URL with unspecified error_description',
{
error: params.error || 'unspecified_error',
code: params.error_code || 'unspecified_code',
}
)
}

const {
provider_token,
provider_refresh_token,
Expand Down

0 comments on commit ab7630f

Please sign in to comment.