From d887f190cd9f100c6f3767d27a30928fde4f010d Mon Sep 17 00:00:00 2001 From: Samir Chatwiti Date: Fri, 10 Apr 2026 10:20:15 +0100 Subject: [PATCH] fix(gotrue): replace assert with AuthException for PKCE asyncStorage check Added error handling for missing OAuth URL and updated PKCE flow storage check. --- packages/gotrue/lib/src/gotrue_client.dart | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/packages/gotrue/lib/src/gotrue_client.dart b/packages/gotrue/lib/src/gotrue_client.dart index 7a49cd245..035b66939 100644 --- a/packages/gotrue/lib/src/gotrue_client.dart +++ b/packages/gotrue/lib/src/gotrue_client.dart @@ -1069,7 +1069,14 @@ class GoTrueClient { jwt: _currentSession?.accessToken, ), ); - return OAuthResponse(provider: provider, url: res['url']); + final url = res['url'] as String?; + if (url == null) { + throw AuthException( + 'OAuth provider did not return a URL. ' + 'Ensure the provider is enabled in your Supabase project.', + ); + } + return OAuthResponse(provider: provider, url: url); } /// Unlinks an identity from a user by deleting it. @@ -1254,12 +1261,15 @@ class GoTrueClient { urlParams.addAll(queryParams); } if (_flowType == AuthFlowType.pkce) { - assert( - _asyncStorage != null, - 'You need to provide asyncStorage to perform pkce flow.', - ); + final storage = _asyncStorage; + if (storage == null) { + throw AuthException( + 'asyncStorage is required for PKCE flow. ' + 'Provide a GotrueAsyncStorage implementation when initializing GoTrueClient.', + ); + } final codeVerifier = generatePKCEVerifier(); - await _asyncStorage!.setItem( + await storage.setItem( key: '${Constants.defaultStorageKey}-code-verifier', value: codeVerifier, );