From 7501635fbf78c80306e66ae49e4be8423210fdd5 Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Thu, 8 Dec 2022 01:42:14 +0530 Subject: [PATCH] fix: delete use when 2fa is disabled (#5899) Signed-off-by: Udit Takkar Signed-off-by: Udit Takkar --- packages/trpc/server/routers/viewer.tsx | 26 ++++++++++++------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/trpc/server/routers/viewer.tsx b/packages/trpc/server/routers/viewer.tsx index ebcf6e2519..42b6488fc0 100644 --- a/packages/trpc/server/routers/viewer.tsx +++ b/packages/trpc/server/routers/viewer.tsx @@ -230,26 +230,24 @@ const loggedInViewerRouter = router({ throw new Error(ErrorCode.InternalServerError); } + // If user has 2fa enabled, check if input.totpCode is correct const isValidToken = authenticator.check(input.totpCode, secret); if (!isValidToken) { throw new Error(ErrorCode.IncorrectTwoFactorCode); } - // If user has 2fa enabled, check if input.totpCode is correct - // If it is, delete the user from stripe and database - - // Remove me from Stripe - await deleteStripeCustomer(user).catch(console.warn); - - // Remove my account - const deletedUser = await ctx.prisma.user.delete({ - where: { - id: ctx.user.id, - }, - }); - // Sync Services - syncServicesDeleteWebUser(deletedUser); } + // If 2FA is disabled or totpCode is valid then delete the user from stripe and database + await deleteStripeCustomer(user).catch(console.warn); + // Remove my account + const deletedUser = await ctx.prisma.user.delete({ + where: { + id: ctx.user.id, + }, + }); + + // Sync Services + syncServicesDeleteWebUser(deletedUser); return; }), deleteMeWithoutPassword: authedProcedure.mutation(async ({ ctx }) => {