From 10fa30ec0015afb4500e48160492807d910bae4c Mon Sep 17 00:00:00 2001 From: ali ebrahimi Date: Mon, 19 Aug 2024 17:07:44 +0330 Subject: [PATCH] Fix bug in userResolver that is related to return non-updated data for user --- src/resolvers/userResolver.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/resolvers/userResolver.ts b/src/resolvers/userResolver.ts index bf453fba4..508b38c53 100644 --- a/src/resolvers/userResolver.ts +++ b/src/resolvers/userResolver.ts @@ -291,13 +291,19 @@ export class UserResolver { emailConfirmationSentAt: new Date(), }); + const updatedUser = await findUserById(userId); + + if (!updatedUser) { + throw new Error(i18n.__(translationErrorMessagesKeys.USER_NOT_FOUND)); + } + await getNotificationAdapter().sendUserEmailConfirmation({ email, - user: userToVerify, + user: updatedUser, code, }); - return userToVerify; + return updatedUser; } catch (e) { logger.error('userVerificationSendEmailConfirmation() error', e); throw e; @@ -356,7 +362,13 @@ export class UserResolver { emailConfirmationSentAt: null, }); - return userFromDB; + const updatedUser = await findUserById(userId); + + if (!updatedUser) { + throw new Error(i18n.__(translationErrorMessagesKeys.USER_NOT_FOUND)); + } + + return updatedUser; } catch (e) { logger.error('userVerificationConfirmEmail() error', e); throw e;