From 483543db8ef457156877cb9a3f2630358dd423fc Mon Sep 17 00:00:00 2001 From: ali ebrahimi Date: Wed, 14 Aug 2024 13:41:52 +0330 Subject: [PATCH] Reset email verification in email update --- src/entities/user.ts | 2 +- src/resolvers/userResolver.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/entities/user.ts b/src/entities/user.ts index 04e787622..0a0d3e17b 100644 --- a/src/entities/user.ts +++ b/src/entities/user.ts @@ -210,7 +210,7 @@ export class User extends BaseEntity { @Field(_type => Date, { nullable: true }) @Column({ nullable: true }) - emailConfirmedAt: Date; + emailConfirmedAt: Date | null; @Field(_type => Int, { nullable: true }) async donationsCount() { diff --git a/src/resolvers/userResolver.ts b/src/resolvers/userResolver.ts index 393f9c28b..a6150ab55 100644 --- a/src/resolvers/userResolver.ts +++ b/src/resolvers/userResolver.ts @@ -180,6 +180,14 @@ export class UserResolver { if (!validateEmail(email)) { throw new Error(i18n.__(translationErrorMessagesKeys.INVALID_EMAIL)); } + if (dbUser.email !== email) { + dbUser.emailConfirmed = false; + dbUser.emailConfirmationSent = false; + dbUser.emailConfirmationToken = null; + dbUser.emailConfirmationTokenExpiredAt = null; + dbUser.emailConfirmationSentAt = null; + dbUser.emailConfirmedAt = null; + } dbUser.email = email; } if (url !== undefined) {