Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions .github/workflows/supabase_flutter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
38 changes: 13 additions & 25 deletions packages/supabase_flutter/lib/src/supabase_auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/supabase_flutter/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
30 changes: 3 additions & 27 deletions packages/supabase_flutter/test/deep_link_test.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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(
Expand All @@ -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');
});
Expand Down