Skip to content

fix: return to app after Android OAuth callback#509

Merged
9thLevelSoftware merged 2 commits into
mainfrom
fix/phoenix-issue-508-android-oauth-return
Jun 7, 2026
Merged

fix: return to app after Android OAuth callback#509
9thLevelSoftware merged 2 commits into
mainfrom
fix/phoenix-issue-508-android-oauth-return

Conversation

@9thLevelSoftware

Copy link
Copy Markdown
Owner

Summary

  • Explicitly routes Android OAuth redirects back to MainActivity after callback delivery/cancellation.
  • Preserves the existing AndroidOAuthBridge handoff and OAuth token/provider logic.
  • Documents the task/flag rationale for the Custom Tab + empty-affinity redirect activity case.

RCA summary

Android OAuth linking succeeds in the data path, but OAuthRedirectActivity only delivered the callback and finished. Because the Custom Tab flow is launched with FLAG_ACTIVITY_NEW_TASK and the redirect activity uses its own transient task, Android could leave users on the browser/loading surface even though the account was linked.

Tests / verification

  • git diff --check
  • Spec-compliance review subagent: PASS, no blocking findings
  • Code-quality review subagent: PASS, no blocking findings
  • Attempted ./gradlew :androidApp:compileDebugKotlin -Pskip.supabase.check=true --no-daemon but the cron host has no Java runtime installed (Unable to locate a Java Runtime), so Gradle compilation could not run in this environment.

Manual QA recommended

  • On Android, go to Settings → Link Portal Account.
  • Complete Google/Apple OAuth.
  • Verify the app is foregrounded on the linked-account/success state without manually closing the browser/Custom Tab.

Fixes #508

User retains final merge approval; this automation will not merge.

Copilot AI review requested due to automatic review settings June 7, 2026 12:23

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request updates OAuthRedirectActivity to explicitly route the user back to MainActivity after handling the OAuth callback, preventing them from being stranded on the Custom Tab surface. Feedback suggests disabling transition animations with overridePendingTransition(0, 0) to avoid jarring visual effects, and removing the FLAG_ACTIVITY_CLEAR_TOP flag to preserve user context by not destroying other activities on top of MainActivity.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

private fun routeBackToApp() {
val launchIntent = buildReturnToAppIntent()
try {
startActivity(launchIntent)

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.

medium

To prevent jarring window animations (such as a sudden slide or fade of MainActivity) when returning to the app, we can disable the activity transition animations immediately after starting the activity.

            startActivity(launchIntent)
            @Suppress("DEPRECATION")
            overridePendingTransition(0, 0)

Comment on lines +110 to +114
addFlags(
Intent.FLAG_ACTIVITY_NEW_TASK or
Intent.FLAG_ACTIVITY_CLEAR_TOP or
Intent.FLAG_ACTIVITY_SINGLE_TOP,
)

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.

medium

Using Intent.FLAG_ACTIVITY_CLEAR_TOP will clear any activities on top of MainActivity when bringing the task to the front. If the app is ever expanded to use multiple activities, this flag would destroy those activities and force the user back to the root MainActivity, losing their current context (e.g., if they initiated the OAuth flow from a settings or profile sub-activity).

Since Intent.FLAG_ACTIVITY_NEW_TASK combined with Intent.FLAG_ACTIVITY_SINGLE_TOP is sufficient to bring the existing task to the front and safely reuse the MainActivity instance (or resume the top-most activity of the task), we can remove FLAG_ACTIVITY_CLEAR_TOP to preserve user context and make the task routing more future-proof.

            addFlags(
                Intent.FLAG_ACTIVITY_NEW_TASK or
                    Intent.FLAG_ACTIVITY_SINGLE_TOP,
            )

@9thLevelSoftware

Copy link
Copy Markdown
Owner Author

Addressed automated review feedback in 36e3ff7: replaced CLEAR_TOP with REORDER_TO_FRONT to preserve the existing app stack/link-account context, and suppressed transition animation after routing back to MainActivity.

@kilo-code-bot

kilo-code-bot Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Code Review Roast 🔥

Verdict: No Issues Found | Recommendation: Merge

Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything.

The author fixed the exact UX problem you'd expect from the issue description: users getting stranded on Custom Tab after OAuth. The routeBackToApp() implementation with NEW_TASK | REORDER_TO_FRONT | SINGLE_TOP is the correct incantation for an empty-affinity singleTask redirect activity. The try-catch is appropriately defensive, and the KDoc explains the Android task model better than most Stack Overflow answers.

Still surprised to see a PR this tight on the first swing. Usually there's at least one // TODO: fix this hack breadcrumb.

📊 Overall: Like finding a well-commented Android task management solution — mythical, but real.

Files Reviewed (1 file)
  • androidApp/src/main/kotlin/com/devil/phoenixproject/auth/OAuthRedirectActivity.kt - 0 issues

Reviewed by laguna-m.1-20260312:free · 384,902 tokens

@9thLevelSoftware 9thLevelSoftware merged commit 8a22b7d into main Jun 7, 2026
10 checks passed
@9thLevelSoftware 9thLevelSoftware deleted the fix/phoenix-issue-508-android-oauth-return branch June 7, 2026 13:29
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.

Android OAuth linking hangs after account selection despite success

2 participants