Skip to content

Staging#88

Merged
Shashank0701-byte merged 2 commits intomainfrom
staging
Mar 26, 2026
Merged

Staging#88
Shashank0701-byte merged 2 commits intomainfrom
staging

Conversation

@Shashank0701-byte
Copy link
Copy Markdown
Owner

@Shashank0701-byte Shashank0701-byte commented Mar 26, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved error messaging during Google and GitHub sign-in flows to clearly communicate when an account with the provided email address already exists using a different authentication method, helping users understand the necessary steps for account recovery and credential linking.

- Firebase is blocking github login
- Added better error message
- Error handling now pretty and better
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
system-craft Ready Ready Preview, Comment Mar 26, 2026 0:44am

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 26, 2026

📝 Walkthrough

Walkthrough

Enhanced Google and GitHub sign-in flows to detect account credential conflicts and generate user-friendly error messages. When an email is already associated with different sign-in methods, the system now retrieves and displays those existing methods instead of showing a generic error.

Changes

Cohort / File(s) Summary
Authentication Error Handling
src/lib/firebase/auth.ts
Added fetchSignInMethodsForEmail integration to detect auth/account-exists-with-different-credential errors. Introduced formatProviderName and buildProviderConflictMessage helper functions to generate user-facing messages displaying existing sign-in methods. Updated signInWithGoogle and signInWithGitHub to catch and rethrow credential conflicts with formatted messages, with fallback to generic guidance.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit hops through auth's domain,
Where conflicts once caused user pain,
Now messages bright, so clear and true,
"Use Google!" or "GitHub!" will show you through!
No more confusion, just friendly advice—
Sign-in made better, oh isn't that nice! 🎉

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

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.
Title check ❓ Inconclusive The title 'Staging' is vague and does not describe the actual changes made in the pull request, which involve adding error handling for credential conflicts during social sign-in. Use a more descriptive title that reflects the main change, such as 'Handle credential conflict errors in social sign-in' or 'Add account-exists-with-different-credential error handling'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch staging

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.

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 26, 2026

Deploy Preview for system-craft-staging ready!

Name Link
🔨 Latest commit 6290fa1
🔍 Latest deploy log https://app.netlify.com/projects/system-craft-staging/deploys/69c52228aecbc900080511ac
😎 Deploy Preview https://deploy-preview-88--system-craft-staging.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

@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.

🧹 Nitpick comments (2)
src/lib/firebase/auth.ts (2)

63-65: Consider a shared OAuth popup helper to remove duplication.

The Google/GitHub conflict branches are now structurally identical; extracting a shared helper will reduce drift risk.

♻️ Example direction
+const signInWithOAuthPopup = async (
+    provider: GoogleAuthProvider | GithubAuthProvider,
+    attemptedProvider: "Google" | "GitHub",
+    label: "Google" | "GitHub"
+) => {
+    if (!auth) throw new Error("Firebase Auth is not initialized.");
+    try {
+        const res = await signInWithPopup(auth, provider);
+        return res.user;
+    } catch (error) {
+        const authError = error as AuthError;
+        console.error(`${label} sign-in error:`, {
+            code: authError.code,
+            message: authError.message,
+        });
+        if (authError.code === "auth/account-exists-with-different-credential") {
+            throw new Error(await buildProviderConflictMessage(authError, attemptedProvider));
+        }
+        throw new Error(authError.message || `Failed to sign in with ${label}`);
+    }
+};
+
 export const signInWithGoogle = async () => {
-    if (!auth) throw new Error("Firebase Auth is not initialized.");
-    try {
-        const res = await signInWithPopup(auth, googleProvider);
-        return res.user;
-    } catch (error) {
-        const authError = error as AuthError;
-        console.error("Google sign-in error:", {
-            code: authError.code,
-            message: authError.message,
-        });
-        if (authError.code === "auth/account-exists-with-different-credential") {
-            throw new Error(await buildProviderConflictMessage(authError, "Google"));
-        }
-        throw new Error(authError.message || "Failed to sign in with Google");
-    }
+    return signInWithOAuthPopup(googleProvider, "Google", "Google");
 };
 
 export const signInWithGitHub = async () => {
-    if (!auth) throw new Error("Firebase Auth is not initialized.");
-    try {
-        const res = await signInWithPopup(auth, githubProvider);
-        return res.user;
-    } catch (error) {
-        const authError = error as AuthError;
-        console.error("GitHub sign-in error:", {
-            code: authError.code,
-            message: authError.message,
-        });
-        if (authError.code === "auth/account-exists-with-different-credential") {
-            throw new Error(await buildProviderConflictMessage(authError, "GitHub"));
-        }
-        throw new Error(authError.message || "Failed to sign in with GitHub");
-    }
+    return signInWithOAuthPopup(githubProvider, "GitHub", "GitHub");
 };

Also applies to: 81-83

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/firebase/auth.ts` around lines 63 - 65, The two branches handling
provider-conflict errors (the authError.code ===
"auth/account-exists-with-different-credential" blocks at the Google and GitHub
sign-in sites) are identical; extract a shared helper (e.g.,
handleProviderConflict or buildAndThrowProviderConflict) that takes the
authError and provider name and throws new Error(await
buildProviderConflictMessage(...)); then replace both duplicated branches to
call that helper from the Google and GitHub sign-in code paths so the logic
lives in one place (reference buildProviderConflictMessage and the authError
checks).

34-49: Extract the repeated fallback message constant.

The same fallback string appears 3 times, which makes future copy edits error-prone.

♻️ Proposed cleanup
 async function buildProviderConflictMessage(authError: AuthError, attemptedProvider: "Google" | "GitHub") {
     const email = authError.customData?.email;
+    const fallbackMessage =
+        `An account already exists with this email. Sign in using the original method first, then connect ${attemptedProvider} later.`;

     if (!auth || !email) {
-        return `An account already exists with this email. Sign in using the original method first, then connect ${attemptedProvider} later.`;
+        return fallbackMessage;
     }

     try {
         const methods = await fetchSignInMethodsForEmail(auth, email);

         if (methods.length === 0) {
-            return `An account already exists with this email. Sign in using the original method first, then connect ${attemptedProvider} later.`;
+            return fallbackMessage;
         }

         const formattedMethods = methods.map(formatProviderName).join(" or ");
         return `This email is already registered with ${formattedMethods}. Sign in using ${formattedMethods} first, then connect ${attemptedProvider} later.`;
     } catch {
-        return `An account already exists with this email. Sign in using the original method first, then connect ${attemptedProvider} later.`;
+        return fallbackMessage;
     }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/lib/firebase/auth.ts` around lines 34 - 49, Extract the repeated fallback
string into a single constant (e.g., FALLBACK_EMAIL_EXISTS_MSG) and replace the
three inline occurrences with that constant; update the logic around
fetchSignInMethodsForEmail, methods.map(formatProviderName) and the catch block
to reference the new constant while preserving the dynamic attemptedProvider
interpolation where needed (compose the final message by either returning the
constant directly or using a template that inserts attemptedProvider). Ensure
the constant is declared near the top of the module and used in the
early-return, methods.length === 0 branch, and the catch branch to avoid
duplication.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/lib/firebase/auth.ts`:
- Around line 63-65: The two branches handling provider-conflict errors (the
authError.code === "auth/account-exists-with-different-credential" blocks at the
Google and GitHub sign-in sites) are identical; extract a shared helper (e.g.,
handleProviderConflict or buildAndThrowProviderConflict) that takes the
authError and provider name and throws new Error(await
buildProviderConflictMessage(...)); then replace both duplicated branches to
call that helper from the Google and GitHub sign-in code paths so the logic
lives in one place (reference buildProviderConflictMessage and the authError
checks).
- Around line 34-49: Extract the repeated fallback string into a single constant
(e.g., FALLBACK_EMAIL_EXISTS_MSG) and replace the three inline occurrences with
that constant; update the logic around fetchSignInMethodsForEmail,
methods.map(formatProviderName) and the catch block to reference the new
constant while preserving the dynamic attemptedProvider interpolation where
needed (compose the final message by either returning the constant directly or
using a template that inserts attemptedProvider). Ensure the constant is
declared near the top of the module and used in the early-return, methods.length
=== 0 branch, and the catch branch to avoid duplication.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: edf22b28-4685-4139-8858-ff546c89786f

📥 Commits

Reviewing files that changed from the base of the PR and between 1fa4f39 and 6290fa1.

📒 Files selected for processing (1)
  • src/lib/firebase/auth.ts

@Shashank0701-byte Shashank0701-byte merged commit 820f7bc into main Mar 26, 2026
9 checks passed
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.

1 participant