From 2b2ae7251c8776144ef7e00f30cb5929091da403 Mon Sep 17 00:00:00 2001 From: Nishad Date: Fri, 1 Mar 2024 17:25:49 +0530 Subject: [PATCH] fixed the forgot password for old supabase user Signed-off-by: Nishad --- apps/user/src/user.service.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/apps/user/src/user.service.ts b/apps/user/src/user.service.ts index f9e112b41..b9aefd058 100644 --- a/apps/user/src/user.service.ts +++ b/apps/user/src/user.service.ts @@ -470,11 +470,21 @@ export class UserService { } const decryptedPassword = await this.commonService.decryptPassword(password); - try { + try { + const authToken = await this.clientRegistrationService.getManagementToken(); userData.password = decryptedPassword; - await this.clientRegistrationService.resetPasswordOfUser(userData, process.env.KEYCLOAK_REALM, authToken); + if (userData.keycloakUserId) { + await this.clientRegistrationService.resetPasswordOfUser(userData, process.env.KEYCLOAK_REALM, authToken); + } else { + const keycloakDetails = await this.clientRegistrationService.createUser(userData, process.env.KEYCLOAK_REALM, authToken); + await this.userRepository.updateUserDetails(userData.id, + keycloakDetails.keycloakUserId.toString() + ); + } + await this.updateFidoVerifiedUser(email.toLowerCase(), userData.isFidoVerified, password); + } catch (error) { this.logger.error(`Error reseting the password`, error); throw new InternalServerErrorException('Error while reseting user password');