From d7234aed1c8ef18b80b215e338fe89a62da55bdc Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Tue, 30 Sep 2025 21:08:22 +0000 Subject: [PATCH] Prevent unlinking final login method cgen-84fe1c3d42ef4baeb63a696d59b58bc4 --- client/contexts/AuthContext.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/client/contexts/AuthContext.tsx b/client/contexts/AuthContext.tsx index 9f83aea0..3fa1ec57 100644 --- a/client/contexts/AuthContext.tsx +++ b/client/contexts/AuthContext.tsx @@ -378,6 +378,22 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ }); return; } + + const identities = (user.identities ?? []) as any[]; + const supportedLinkedCount = identities.filter((item: any) => + ["github", "google"].includes(item.provider), + ).length; + const hasEmailIdentity = identities.some( + (item: any) => item.provider === "email", + ); + if (!hasEmailIdentity && supportedLinkedCount <= 1) { + aethexToast.error({ + title: "Cannot unlink provider", + description: + "Add another sign-in method before removing this connection.", + }); + return; + } try { const { error } = (await supabase.auth.unlinkIdentity({ identity_id: identity.identity_id,