-
-
Notifications
You must be signed in to change notification settings - Fork 8
fix: resolve bounty issue #5 - save user data before sign out on email collision #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -186,9 +186,9 @@ private void verifyCredential(PhoneAuthCredential credential) { | |
| String msg = e != null ? e.getMessage() : "Unknown linking error"; | ||
|
|
||
| if (e instanceof FirebaseAuthUserCollisionException) { | ||
| Toast.makeText(OTPActivity.this, | ||
| "This email is already registered with a different account. Please login with that email or use another email.", | ||
| Toast.LENGTH_LONG).show(); | ||
| // Email already exists with different account. | ||
| // Save phone-based user data to Firestore first, then redirect to login. | ||
| saveUserToFirestoreOnCollision(uid, name, email, number, password); | ||
| } else { | ||
| Toast.makeText(OTPActivity.this, | ||
| "Failed to link email: " + msg, | ||
|
|
@@ -199,6 +199,49 @@ private void verifyCredential(PhoneAuthCredential credential) { | |
| }); | ||
| } | ||
|
|
||
| private void saveUserToFirestoreOnCollision(String uid, String name, String email, String number, String password) { | ||
| if (name == null) name = ""; | ||
| if (email == null) email = ""; | ||
| if (number == null) number = ""; | ||
| if (password == null) password = ""; | ||
|
|
||
| UserModel user = new UserModel( | ||
| name, | ||
| email, | ||
| number, | ||
| password, | ||
| "https://firebasestorage.googleapis.com/v0/b/earning-b8942.firebasestorage.app/o/account.png?alt=media&token=***" | ||
| ); | ||
|
|
||
| if (dialog.isShowing()) dialog.dismiss(); | ||
|
|
||
| firestore.collection("users") | ||
| .document(uid) | ||
| .set(user) | ||
| .addOnSuccessListener(unused -> { | ||
| // User data saved successfully. Now sign out and redirect to login. | ||
| auth.signOut(); | ||
| Toast.makeText(OTPActivity.this, | ||
| "An account with this email already exists. Please login with your email and password.", | ||
| Toast.LENGTH_LONG).show(); | ||
| Intent intent = new Intent(OTPActivity.this, LoginActivity.class); | ||
| intent.putExtra("prefilled_email", email); | ||
| startActivity(intent); | ||
| finish(); | ||
| }) | ||
| .addOnFailureListener(e -> { | ||
| // Failed to save - still redirect to login with email prefilled. | ||
| auth.signOut(); | ||
| Toast.makeText(OTPActivity.this, | ||
| "Failed to link email: " + e.getMessage() + ". Please login with your existing account.", | ||
| Toast.LENGTH_LONG).show(); | ||
| Intent intent = new Intent(OTPActivity.this, LoginActivity.class); | ||
| intent.putExtra("prefilled_email", email); | ||
| startActivity(intent); | ||
| finish(); | ||
| }); | ||
| } | ||
|
Comment on lines
+202
to
+243
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Compile error: The parameters 🐛 Proposed fix using final local variables private void saveUserToFirestoreOnCollision(String uid, String name, String email, String number, String password) {
- if (name == null) name = "";
- if (email == null) email = "";
- if (number == null) number = "";
- if (password == null) password = "";
+ final String safeName = (name == null) ? "" : name;
+ final String safeEmail = (email == null) ? "" : email;
+ final String safeNumber = (number == null) ? "" : number;
+ final String safePassword = (password == null) ? "" : password;
UserModel user = new UserModel(
- name,
- email,
- number,
- password,
+ safeName,
+ safeEmail,
+ safeNumber,
+ safePassword,
"https://firebasestorage.googleapis.com/v0/b/earning-b8942.firebasestorage.app/o/account.png?alt=media&token=***"
);
if (dialog.isShowing()) dialog.dismiss();
firestore.collection("users")
.document(uid)
.set(user)
.addOnSuccessListener(unused -> {
// User data saved successfully. Now sign out and redirect to login.
auth.signOut();
Toast.makeText(OTPActivity.this,
"An account with this email already exists. Please login with your email and password.",
Toast.LENGTH_LONG).show();
Intent intent = new Intent(OTPActivity.this, LoginActivity.class);
- intent.putExtra("prefilled_email", email);
+ intent.putExtra("prefilled_email", safeEmail);
startActivity(intent);
finish();
})
.addOnFailureListener(e -> {
// Failed to save - still redirect to login with email prefilled.
auth.signOut();
Toast.makeText(OTPActivity.this,
"Failed to link email: " + e.getMessage() + ". Please login with your existing account.",
Toast.LENGTH_LONG).show();
Intent intent = new Intent(OTPActivity.this, LoginActivity.class);
- intent.putExtra("prefilled_email", email);
+ intent.putExtra("prefilled_email", safeEmail);
startActivity(intent);
finish();
});
}🤖 Prompt for AI Agents |
||
|
|
||
| private void saveUserToFirestoreAndContinue(String uid, String name, String email, String number, String password) { | ||
|
|
||
| if (name == null) name = ""; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Placeholder token will produce broken profile images.
The image URL uses
token=***while the existing method at line 257 uses the actual token. Users created through the collision flow will have invalid profile image URLs. Use the same token or extract the URL to a constant.🐛 Proposed fix
Consider extracting this URL to a constant to avoid duplication:
📝 Committable suggestion
🤖 Prompt for AI Agents