diff --git a/src/GoTrueClient.ts b/src/GoTrueClient.ts index b01b16e0..ed60cc81 100644 --- a/src/GoTrueClient.ts +++ b/src/GoTrueClient.ts @@ -1422,6 +1422,17 @@ 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.') @@ -1429,8 +1440,6 @@ export default class GoTrueClient { 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) @@ -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,