Skip to content

fix(android): launch auth in CustomTab - #10371

Merged
jamilbk merged 4 commits into
mainfrom
fix/android-custom-tabs
Sep 18, 2025
Merged

jamilbk merged 4 commits into
mainfrom
fix/android-custom-tabs

Conversation

@jamilbk

@jamilbk jamilbk commented Sep 18, 2025

Copy link
Copy Markdown
Member

Unfortunately, Firefox on Android seems to have a bug where it only allows one tab to intercept the custom URI scheme handler for our auth redirect. This causes an issue where the first sign in works, but subsequent ones do not because that first tab is still open.

Luckily the fix here is quite simple. By using Android's CustomTabs to launch the activity, only one, sandboxed instance is ever open and the URI intercept works reliably. Both Firefox and Chrome (and likely other browsers) support CustomTabs, which means the user's default browser is used, allowing cookies, password managers, etc to be used.

Related to this, this PR also fixes a bug where dismissing the launched auth flow would result in it immediately relaunching, making it impossible to get back to the app unless you force quit or complete the sign in process.

Fixes #10318

Unfortunately, Firefox on Android seems to have a bug where it only
allows one tab to intercept the custom URI scheme handler for our auth
redirect. This causes an issue where the first sign in works, but
subsequent ones do not because that first tab is still open.

Luckily the fix here is quite simple. By using Android's CustomTabs to
launch the activity, only one, sandboxed instance is ever open and the
URI intercept works reliably. Both Firefox and Chrome (and likely other
browsers) support CustomTabs, which means the user's default browser is
used, allowing cookies, password managers, etc to be used.

Related to this, this PR also fixes a bug where dismissing the launched
auth flow would result in it immediately relaunching, making it
impossible to get back to the app unless you force quit or complete the
sign in process.

Fixes #10318
@vercel

vercel Bot commented Sep 18, 2025 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
firezone Ready Ready Preview Comment Sep 18, 2025 2:23am

@jamilbk

jamilbk commented Sep 18, 2025

Copy link
Copy Markdown
Member Author

Tested:

  • Android 16 simulator
  • Android 15 physical device

@jamilbk
jamilbk marked this pull request as ready for review September 18, 2025 02:06
Copilot AI review requested due to automatic review settings September 18, 2025 02:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes authentication issues on Android by implementing CustomTabs for OAuth flows and preventing infinite relaunch loops. The change addresses a Firefox bug where multiple tabs interfere with URI scheme handling, causing subsequent sign-ins to fail.

  • Replaces standard browser intent with Android CustomTabs for authentication
  • Adds logic to prevent auth flow from relaunching when user dismisses it
  • Includes changelog entry documenting the Firefox-specific fix

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
website/src/components/Changelog/Android.tsx Adds changelog entry for Firefox sign-in bug fix
kotlin/android/app/src/main/java/dev/firezone/android/features/auth/ui/AuthViewModel.kt Simplifies auth URL construction and removes unused authFlowLaunched variable
kotlin/android/app/src/main/java/dev/firezone/android/features/auth/ui/AuthActivity.kt Implements CustomTabs for auth flow and adds dismissal handling logic

Comment on lines +65 to +70
} catch (e: Exception) {
// Fallback to default browser if Custom Tabs unavailable
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
startActivity(intent)
}

Copilot AI Sep 18, 2025

Copy link

Choose a reason for hiding this comment

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

The catch block should handle specific exceptions rather than catching all exceptions. Consider catching ActivityNotFoundException specifically, as this is the most likely exception when CustomTabs are unavailable.

Copilot uses AI. Check for mistakes.
Comment on lines +32 to +37
if (hasLaunchedCustomTab) {
// User returned from Custom Tab without completing auth, navigate back to main app
navigateToSignIn()
} else {
viewModel.onActivityResume()
}

Copilot AI Sep 18, 2025

Copy link

Choose a reason for hiding this comment

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

The logic assumes that returning to onResume after launching CustomTab means auth was dismissed, but this could also trigger if the user switches apps and returns. Consider using onNewIntent() to handle the auth callback specifically, or check for the auth result before assuming dismissal.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think this is ok - switching to another app and returning while the custom tab is open does not close it.

@thomaseizinger thomaseizinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work. Testing this now on my device.

@jamilbk
jamilbk added this pull request to the merge queue Sep 18, 2025
@thomaseizinger

Copy link
Copy Markdown
Member

Great fix! This is a much nicer experience because it also doesn't leave that odd "You are signed in" tab behind.

Merged via the queue into main with commit f2ff5df Sep 18, 2025
28 checks passed

This branch was successfully deployed

1 active deployment
Preview — 1229111c Deployed Sep 18, 2025 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Repeated sign-ins on Android don't work

3 participants