From 65fea3ce45eaa5e3318acee56d6afb27afbd9508 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Tue, 11 Nov 2025 22:08:52 +0000 Subject: [PATCH] completionId: cgen-21d129e4101b4d48a240419f117d5df5 cgen-21d129e4101b4d48a240419f117d5df5 --- client/contexts/AuthContext.tsx | 38 ++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/client/contexts/AuthContext.tsx b/client/contexts/AuthContext.tsx index f587ebc7..af0a43ea 100644 --- a/client/contexts/AuthContext.tsx +++ b/client/contexts/AuthContext.tsx @@ -490,11 +490,47 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ throw new Error("Please provide both email and password."); } - const { data, error } = await supabase.auth.signInWithPassword({ + // First attempt: try signing in with the provided email + let { data, error } = await supabase.auth.signInWithPassword({ email, password, }); + // If invalid credentials and it might be a linked email, try to resolve it + if ( + error && + (error.message?.includes("Invalid login credentials") || + error.message?.includes("invalid email")) + ) { + try { + // Check if this email is linked to another account + const response = await fetch("/api/user/resolve-linked-email", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ email }), + }); + + if (response.ok) { + const { primaryEmail } = await response.json(); + if (primaryEmail && primaryEmail !== email) { + // Try signing in with the primary email + const retryResult = await supabase.auth.signInWithPassword({ + email: primaryEmail, + password, + }); + + if (!retryResult.error) { + data = retryResult.data; + error = null; + } + } + } + } catch (e) { + // If email resolution fails, continue with original error + console.error("Email resolution failed:", e); + } + } + if (error) throw error; try {