fix: resolve bounty issue #5 - handle FirebaseAuthUserCollisionException properly#15
Conversation
…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.
📝 WalkthroughWalkthroughThis 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. ChangesEmail Collision Redirect
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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.
Built for teams:
One agent for your entire SDLC. Right inside Slack. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
app/src/main/java/com/example/updateapp/views/activites/OTPActivity.java (1)
195-196: ⚡ Quick winCentralize the
prefilled_emailintent key.This flow now depends on the same raw string in both
OTPActivityandLoginActivity. 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
📒 Files selected for processing (2)
app/src/main/java/com/example/updateapp/views/activites/LoginActivity.javaapp/src/main/java/com/example/updateapp/views/activites/OTPActivity.java
| 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(); |
There was a problem hiding this comment.
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.
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 withFirebaseAuthUserCollisionException(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
FirebaseAuthUserCollisionExceptionoccurs:auth.signOut())LoginActivitywith the email pre-filledAlso added
prefilled_emailhandling inLoginActivityto auto-fill the email field when redirected from OTP screen.Files changed
OTPActivity.java- handle collision exception by signing out and redirectingLoginActivity.java- handle prefilled email from intentCloses #5
Summary by CodeRabbit
New Features
Bug Fixes