feat: new route added for deletion (#5160)

* feat: new route added for deletion
required password removed from update profile

* fix: update url

Co-authored-by: alannnc <[email protected]>
Co-authored-by: Peer Richelsen <[email protected]>
This commit is contained in:
authored and GitHub committed 2022-10-24 18:32:00 -06:00
1 parent 317909d20a
commit 2d5bf1ffc1
4 files changed
+74 -18

No files matched your search

+1
View File
@@ -75,6 +75,7 @@ export enum ErrorCode {
NewPasswordMatchesOld = "new-password-matches-old",
ThirdPartyIdentityProviderEnabled = "third-party-identity-provider-enabled",
RateLimitExceeded = "rate-limit-exceeded",
SocialIdentityProviderRequired = "social-identity-provider-required",
}
export const identityProviderNameMap: { [key in IdentityProvider]: string } = {
+34
View File
@@ -246,6 +246,40 @@ const loggedInViewerRouter = createProtectedRouter()
return;
},
})
.mutation("deleteMeWithoutPassword", {
async resolve({ ctx }) {
const user = await prisma.user.findUnique({
where: {
email: ctx.user.email.toLowerCase(),
},
});
if (!user) {
throw new Error(ErrorCode.UserNotFound);
}
if (user.identityProvider === IdentityProvider.CAL) {
throw new Error(ErrorCode.SocialIdentityProviderRequired);
}
if (user.twoFactorEnabled) {
throw new Error(ErrorCode.SocialIdentityProviderRequired);
}
// 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);
return;
},
})
.mutation("away", {
input: z.object({
away: z.boolean(),