@@ -1423,14 +1423,29 @@ export default class GoTrueClient {
1423
1423
> {
1424
1424
try {
1425
1425
if ( ! isBrowser ( ) ) throw new AuthImplicitGrantRedirectError ( 'No browser detected.' )
1426
+
1427
+ const params = parseParametersFromURL ( window . location . href )
1428
+
1429
+ // If there's an error in the URL, it doesn't matter what flow it is, we just return the error.
1430
+ if ( params . error || params . error_description || params . error_code ) {
1431
+ // The error class returned implies that the redirect is from an implicit grant flow
1432
+ // but it could also be from a redirect error from a PKCE flow.
1433
+ throw new AuthImplicitGrantRedirectError (
1434
+ params . error_description || 'Error in URL with unspecified error_description' ,
1435
+ {
1436
+ error : params . error || 'unspecified_error' ,
1437
+ code : params . error_code || 'unspecified_code' ,
1438
+ }
1439
+ )
1440
+ }
1441
+
1442
+ // Checks for mismatches between the flowType initialised in the client and the URL parameters
1426
1443
if ( this . flowType === 'implicit' && ! this . _isImplicitGrantFlow ( ) ) {
1427
1444
throw new AuthImplicitGrantRedirectError ( 'Not a valid implicit grant flow url.' )
1428
1445
} else if ( this . flowType == 'pkce' && ! isPKCEFlow ) {
1429
1446
throw new AuthPKCEGrantCodeExchangeError ( 'Not a valid PKCE flow url.' )
1430
1447
}
1431
1448
1432
- const params = parseParametersFromURL ( window . location . href )
1433
-
1434
1449
if ( isPKCEFlow ) {
1435
1450
if ( ! params . code ) throw new AuthPKCEGrantCodeExchangeError ( 'No code detected.' )
1436
1451
const { data, error } = await this . _exchangeCodeForSession ( params . code )
@@ -1444,16 +1459,6 @@ export default class GoTrueClient {
1444
1459
return { data : { session : data . session , redirectType : null } , error : null }
1445
1460
}
1446
1461
1447
- if ( params . error || params . error_description || params . error_code ) {
1448
- throw new AuthImplicitGrantRedirectError (
1449
- params . error_description || 'Error in URL with unspecified error_description' ,
1450
- {
1451
- error : params . error || 'unspecified_error' ,
1452
- code : params . error_code || 'unspecified_code' ,
1453
- }
1454
- )
1455
- }
1456
-
1457
1462
const {
1458
1463
provider_token,
1459
1464
provider_refresh_token,
0 commit comments