Skip to content
Closed
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
18 changes: 14 additions & 4 deletions app/lib/providers/auth_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,20 @@ class AuthenticationProvider extends BaseProvider {
return;
}

await launchUrl(
uri,
mode: LaunchMode.inAppBrowserView,
);
try {
await launchUrl(
uri,
mode: LaunchMode.inAppBrowserView,
);
} catch (e) {
Logger.debug('Failed to launch URL: $e');
// Fallback to external browser if in-app browser fails
try {
await launchUrl(uri, mode: LaunchMode.externalApplication);
} catch (e) {
Logger.debug('Failed to launch URL externally: $e');
}
}
Comment on lines +183 to +196
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The current implementation correctly handles exceptions when launching the URL, which fixes the reported crash. However, launchUrl can also return false on failure without throwing an exception. In that case, the fallback to an external browser would not be triggered, leading to a silent failure.

To make the implementation more robust, we should also handle the false return value from launchUrl. The suggested change refactors the logic to catch both exceptions and false return values from the in-app launch attempt, and then proceeds to the fallback in either case.

    try {
      if (!await launchUrl(uri, mode: LaunchMode.inAppBrowserView)) {
        throw Exception('launchUrl returned false');
      }
    } catch (e) {
      Logger.debug('Failed to launch URL in-app, falling back: $e');

      try {
        if (!await launchUrl(uri, mode: LaunchMode.externalApplication)) {
          Logger.debug('Failed to launch URL externally, launchUrl returned false.');
        }
      } catch (e2) {
        Logger.debug('Failed to launch URL externally: $e2');
      }
    }

}

Future<void> linkWithGoogle() async {
Expand Down