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:
4 files changed
+74
-18
No files matched your search
@@ -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 } = {
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in new issue
Block a user