Prevent unlinking final login method

cgen-84fe1c3d42ef4baeb63a696d59b58bc4
This commit is contained in:
Builder.io 2025-09-30 21:08:22 +00:00
parent 593e9f2f56
commit d7234aed1c

View file

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