From 014c09bd910a407f974dff880e1c35e10e02ece8 Mon Sep 17 00:00:00 2001 From: Ephraim Atta-Duncan Date: Sun, 28 Jan 2024 18:43:20 +0000 Subject: [PATCH] fix: account deletion error for users without two factor authentication --- apps/web/src/components/forms/profile.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/forms/profile.tsx b/apps/web/src/components/forms/profile.tsx index 575a81d46..80c33dd60 100644 --- a/apps/web/src/components/forms/profile.tsx +++ b/apps/web/src/components/forms/profile.tsx @@ -113,10 +113,26 @@ export const ProfileForm = ({ className, user }: ProfileFormProps) => { } }; - const onDeleteAccount = async () => { + const onDeleteAccount = async (hasTwoFactorAuthentication: boolean) => { try { + if (!hasTwoFactorAuthentication) { + await deleteAccount(); + + toast({ + title: 'Account deleted', + description: 'Your account has been deleted successfully.', + duration: 5000, + }); + + await signOut({ callbackUrl: '/' }); + + return; + } + const { token } = deleteAccountTwoFactorTokenForm.getValues(); + console.log(token); + if (!token) { throw new Error('Please enter your Two Factor Authentication token.'); } @@ -273,7 +289,7 @@ export const ProfileForm = ({ className, user }: ProfileFormProps) => {