Skip to content

fix: resolve bounty issue #5 - handle FirebaseAuthUserCollisionException properly#15

Open
bomlinux92-byte wants to merge 1 commit into
allknowledge34:mainfrom
bomlinux92-byte:bounty-fix-5-20260515
Open

fix: resolve bounty issue #5 - handle FirebaseAuthUserCollisionException properly#15
bomlinux92-byte wants to merge 1 commit into
allknowledge34:mainfrom
bomlinux92-byte:bounty-fix-5-20260515

Conversation

@bomlinux92-byte
Copy link
Copy Markdown

@bomlinux92-byte bomlinux92-byte commented May 14, 2026

Summary

Fix for [BOUNTY $0.40] Login fails with 'Invalid Email' after successful signup and OTP verification — Issue #5

Root cause

When auth.getCurrentUser().linkWithCredential(emailCredential) fails with FirebaseAuthUserCollisionException (email already registered with different account), the code only showed a toast but left the user with an orphaned phone-only account. This phone-only account cannot login with email/password, causing 'Invalid Email' errors.

Fix

When FirebaseAuthUserCollisionException occurs:

  1. Sign out the orphaned phone-only account (auth.signOut())
  2. Redirect user to LoginActivity with the email pre-filled
  3. Show clear message instructing user to login with existing account

Also added prefilled_email handling in LoginActivity to auto-fill the email field when redirected from OTP screen.

Files changed

  • OTPActivity.java - handle collision exception by signing out and redirecting
  • LoginActivity.java - handle prefilled email from intent

Closes #5

Summary by CodeRabbit

  • New Features

    • Login screen now supports email prefilling for faster authentication.
  • Bug Fixes

    • Enhanced email conflict recovery during phone verification with improved session management and clearer user guidance to log in via email/password.

Review Change Stack

…ollisionException properly

When email linking fails with FirebaseAuthUserCollisionException, the user
was left with a phone-only account that cannot login with email/password.

Fix: sign out the orphaned phone-only account and redirect to login screen
with the email pre-filled, so the user can login with the existing account.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 14, 2026

📝 Walkthrough

Walkthrough

This PR adds email collision handling to the authentication flow. When a phone-verified account attempts to link an email address that already exists, OTPActivity now signs out the user, displays an informative toast, and redirects to LoginActivity with the email pre-filled via an intent extra, allowing users to log in directly without re-entering their email.

Changes

Email Collision Redirect

Layer / File(s) Summary
Email collision detection and prefilled login flow
app/src/main/java/com/example/updateapp/views/activites/OTPActivity.java, app/src/main/java/com/example/updateapp/views/activites/LoginActivity.java
OTPActivity detects FirebaseAuthUserCollisionException during email-linking, signs out the current user, shows a toast instructing login with email/password, and navigates to LoginActivity with the email pre-filled via prefilled_email intent extra. LoginActivity reads this extra during onCreate and populates the email input field when present.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A rabbit hops through collision detection,
Where emails exist in new direction,
Sign out, redirect, pre-fill with care,
Login awaits with email laid bare! 🐰✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: handling FirebaseAuthUserCollisionException properly to fix bounty issue #5.
Linked Issues check ✅ Passed The PR fully addresses issue #5 by implementing all required coding changes: signing out orphaned phone-only accounts, redirecting to LoginActivity with prefilled email, and auto-filling email fields.
Out of Scope Changes check ✅ Passed All changes are directly related to resolving the FirebaseAuthUserCollisionException handling as specified in issue #5; no unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
app/src/main/java/com/example/updateapp/views/activites/OTPActivity.java (1)

195-196: ⚡ Quick win

Centralize the prefilled_email intent key.

This flow now depends on the same raw string in both OTPActivity and LoginActivity. Extract it into a shared constant so a future rename does not silently break the redirect/prefill contract.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/com/example/updateapp/views/activites/OTPActivity.java`
around lines 195 - 196, The intent extra key "prefilled_email" is hard-coded in
OTPActivity and duplicated in LoginActivity; define a single public constant
(e.g., public static final String EXTRA_PREFILLED_EMAIL = "prefilled_email") in
LoginActivity or a shared Constants class, replace the raw string in
OTPActivity's Intent.putExtra call to use LoginActivity.EXTRA_PREFILLED_EMAIL
(and update LoginActivity to read that same constant when extracting the extra),
and remove any other usages of the literal to ensure the key is centralized and
consistent across both classes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/src/main/java/com/example/updateapp/views/activites/OTPActivity.java`:
- Around line 192-194: The hardcoded English toast in OTPActivity (the
Toast.makeText call) must be moved to strings.xml: add a new localized string
resource (e.g., name it error_account_exists with the message "An account with
this email already exists. Please login with your email and password."), then
replace the hardcoded text in OTPActivity's Toast.makeText with
getString(R.string.error_account_exists) (or context.getString(...)) so the
message uses Android's localization system. Ensure you update any import/usages
if needed and run a quick strings.xml merge for other locales.

---

Nitpick comments:
In `@app/src/main/java/com/example/updateapp/views/activites/OTPActivity.java`:
- Around line 195-196: The intent extra key "prefilled_email" is hard-coded in
OTPActivity and duplicated in LoginActivity; define a single public constant
(e.g., public static final String EXTRA_PREFILLED_EMAIL = "prefilled_email") in
LoginActivity or a shared Constants class, replace the raw string in
OTPActivity's Intent.putExtra call to use LoginActivity.EXTRA_PREFILLED_EMAIL
(and update LoginActivity to read that same constant when extracting the extra),
and remove any other usages of the literal to ensure the key is centralized and
consistent across both classes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3d5780e3-091f-490e-836a-cd450fb2d2b9

📥 Commits

Reviewing files that changed from the base of the PR and between 2f5069d and e04af23.

📒 Files selected for processing (2)
  • app/src/main/java/com/example/updateapp/views/activites/LoginActivity.java
  • app/src/main/java/com/example/updateapp/views/activites/OTPActivity.java

Comment on lines 192 to 194
Toast.makeText(OTPActivity.this,
"This email is already registered with a different account. Please login with that email or use another email.",
"An account with this email already exists. Please login with your email and password.",
Toast.LENGTH_LONG).show();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Move the collision toast into strings.xml.

This new message is hardcoded in English, so the recovery path bypasses the app's locale handling and will not be translated.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/src/main/java/com/example/updateapp/views/activites/OTPActivity.java`
around lines 192 - 194, The hardcoded English toast in OTPActivity (the
Toast.makeText call) must be moved to strings.xml: add a new localized string
resource (e.g., name it error_account_exists with the message "An account with
this email already exists. Please login with your email and password."), then
replace the hardcoded text in OTPActivity's Toast.makeText with
getString(R.string.error_account_exists) (or context.getString(...)) so the
message uses Android's localization system. Ensure you update any import/usages
if needed and run a quick strings.xml merge for other locales.

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.

$0.4 Bounty : Login fails with "Invalid Email" after successful signup and OTP verification

1 participant