diff --git a/.github/workflows/supabase_flutter.yml b/.github/workflows/supabase_flutter.yml index f5c412d73..cd36b8639 100644 --- a/.github/workflows/supabase_flutter.yml +++ b/.github/workflows/supabase_flutter.yml @@ -75,11 +75,6 @@ jobs: - name: Run unit tests run: flutter test --concurrency=1 - - name: Run tests with downgraded app_links - run: | - flutter pub downgrade app_links - flutter test --concurrency=1 - - name: Build and test web (JS) if: ${{ matrix.os == 'ubuntu-latest' && matrix.flutter-version == '3.x'}} run: | diff --git a/packages/supabase_flutter/lib/src/supabase_auth.dart b/packages/supabase_flutter/lib/src/supabase_auth.dart index ada94a24d..8f161190b 100644 --- a/packages/supabase_flutter/lib/src/supabase_auth.dart +++ b/packages/supabase_flutter/lib/src/supabase_auth.dart @@ -191,34 +191,22 @@ class SupabaseAuth with WidgetsBindingObserver { if (_initialDeeplinkIsHandled) return; _initialDeeplinkIsHandled = true; - try { - Uri? uri; + // Only web needs to handle initial uri. On mobile, the initial uri is + // included in the uriLinkStream. + if (kIsWeb) { try { - // before app_links 6.0.0 - uri = await (_appLinks as dynamic).getInitialAppLink(); - } on NoSuchMethodError catch (_) { - // The AppLinks package contains the initial link in the uriLinkStream - // starting from version 6.0.0. Before this version, getting the - // initial link was done with getInitialAppLink. Being in this catch - // handler means we are in at least version 6.0.0, meaning we do not - // need to handle the initial link manually. - // - // app_links claims that the initial link will be included in the - // `uriLinkStream`, but that is not the case for web - if (kIsWeb) { - uri = await (_appLinks as dynamic).getInitialLink(); + final Uri? uri = await _appLinks.getInitialLink(); + if (uri != null) { + await _handleDeeplink(uri); } + } on PlatformException catch (err, stackTrace) { + _onErrorReceivingDeeplink(err.message ?? err, stackTrace); + // Platform messages may fail but we ignore the exception + } on FormatException catch (err, stackTrace) { + _onErrorReceivingDeeplink(err.message, stackTrace); + } catch (err, stackTrace) { + _onErrorReceivingDeeplink(err, stackTrace); } - if (uri != null) { - await _handleDeeplink(uri); - } - } on PlatformException catch (err, stackTrace) { - _onErrorReceivingDeeplink(err.message ?? err, stackTrace); - // Platform messages may fail but we ignore the exception - } on FormatException catch (err, stackTrace) { - _onErrorReceivingDeeplink(err.message, stackTrace); - } catch (err, stackTrace) { - _onErrorReceivingDeeplink(err, stackTrace); } } diff --git a/packages/supabase_flutter/pubspec.yaml b/packages/supabase_flutter/pubspec.yaml index 8a8f4b39f..b5f8a208b 100644 --- a/packages/supabase_flutter/pubspec.yaml +++ b/packages/supabase_flutter/pubspec.yaml @@ -10,7 +10,7 @@ environment: flutter: '>=3.19.0' dependencies: - app_links: '>=3.5.0 <7.0.0' + app_links: ^6.2.0 async: ^2.11.0 crypto: ^3.0.2 flutter: diff --git a/packages/supabase_flutter/test/deep_link_test.dart b/packages/supabase_flutter/test/deep_link_test.dart index 7bfadf84d..0db027ac7 100644 --- a/packages/supabase_flutter/test/deep_link_test.dart +++ b/packages/supabase_flutter/test/deep_link_test.dart @@ -1,6 +1,5 @@ @TestOn('!browser') -import 'package:app_links/app_links.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:supabase_flutter/supabase_flutter.dart'; @@ -12,34 +11,13 @@ void main() { group('Deep Link with PKCE code', () { late final PkceHttpClient pkceHttpClient; - late final bool mockEventChannel; - - /// Check if the current version of AppLinks uses an explicit call to get - /// the initial link. This is only the case before version 6.0.0, where we - /// can find the getInitialAppLink function. - /// - /// CI pipeline is set so that it tests both app_links newer and older than v6.0.0 - bool appLinksExposesInitialLinkInStream() { - try { - // before app_links 6.0.0 - (AppLinks() as dynamic).getInitialAppLink; - return false; - } on NoSuchMethodError catch (_) { - return true; - } - } setUp(() async { pkceHttpClient = PkceHttpClient(); - // Add initial deep link with a `code` parameter, use method channel if - // we are in a version of AppLinks that use the explcit method for - // getting the initial link. Otherwise we want to mock the event channel - // and put the initial link there. - mockEventChannel = appLinksExposesInitialLinkInStream(); mockAppLink( - mockMethodChannel: !mockEventChannel, - mockEventChannel: mockEventChannel, + mockMethodChannel: false, + mockEventChannel: true, initialLink: 'com.supabase://callback/?code=my-code-verifier', ); await Supabase.initialize( @@ -62,9 +40,7 @@ void main() { () async { // Wait for the initial app link to be handled, as this is an async // process when mocking the event channel. - if (mockEventChannel) { - await Future.delayed(const Duration(milliseconds: 500)); - } + await Future.delayed(const Duration(milliseconds: 500)); expect(pkceHttpClient.requestCount, 1); expect(pkceHttpClient.lastRequestBody['auth_code'], 'my-code-verifier'); });