fix: delete use when 2fa is disabled (#5899)

Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>

Signed-off-by: Udit Takkar <udit.07814802719@cse.mait.ac.in>
pr/5569
Udit Takkar 2022-12-08 01:42:14 +05:30 committed by GitHub
parent 80c96ea5ac
commit 7501635fbf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 14 deletions

View File

@ -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 }) => {