Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(binding.getRoot());

auth = FirebaseAuth.getInstance();

// Handle prefilled email from OTPActivity redirect
String prefilledEmail = getIntent().getStringExtra("prefilled_email");
if (prefilledEmail != null && !prefilledEmail.isEmpty()) {
binding.edtEmail.setText(prefilledEmail);
}

googleBtn = findViewById(R.id.google_btn);
emailBtn = findViewById(R.id.email_btn);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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=***"
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 | 🟠 Major | ⚡ Quick win

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
-            "https://firebasestorage.googleapis.com/v0/b/earning-b8942.firebasestorage.app/o/account.png?alt=media&token=***"
+            "https://firebasestorage.googleapis.com/v0/b/earning-b8942.firebasestorage.app/o/account.png?alt=media&token=0ef08dd9-6b13-4da2-a39f-500cff3cf4f0"

Consider extracting this URL to a constant to avoid duplication:

private static final String DEFAULT_PROFILE_URL = 
    "https://firebasestorage.googleapis.com/v0/b/earning-b8942.firebasestorage.app/o/account.png?alt=media&token=0ef08dd9-6b13-4da2-a39f-500cff3cf4f0";
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"https://firebasestorage.googleapis.com/v0/b/earning-b8942.firebasestorage.app/o/account.png?alt=media&token=***"
"https://firebasestorage.googleapis.com/v0/b/earning-b8942.firebasestorage.app/o/account.png?alt=media&token=0ef08dd9-6b13-4da2-a39f-500cff3cf4f0"
🤖 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` at
line 213, Replace the hardcoded invalid profile URL that contains "token=***"
with the real token used elsewhere (or extract to a shared constant) so both
usages reference the same value; create a private static final String (e.g.,
DEFAULT_PROFILE_URL) and use that constant in OTPActivity where the placeholder
string appears and in the other location that currently uses the actual token to
prevent broken profile images and duplication.

);

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
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 | 🔴 Critical | ⚡ Quick win

Compile error: email is not effectively final.

The parameters name, email, number, and password are conditionally reassigned (lines 203-206), then email is captured in lambda callbacks (lines 228, 239). Java requires variables used in lambdas to be effectively final. This code will fail to compile.

🐛 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
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 202 - 243, In saveUserToFirestoreOnCollision, the method parameters
(name, email, number, password) are reassigned and then captured by lambdas
causing a compile error because they are not effectively final; fix by replacing
the conditional reassignments with new final local variables (e.g., final String
safeName = (name == null ? "" : name), final String safeEmail = (email == null ?
"" : email), etc.) and use these final locals in the UserModel constructor and
inside the addOnSuccessListener/addOnFailureListener callbacks so the lambdas
capture effectively final variables.


private void saveUserToFirestoreAndContinue(String uid, String name, String email, String number, String password) {

if (name == null) name = "";
Expand Down