From cdbb3e325769b10fd7650273fc16820d20401651 Mon Sep 17 00:00:00 2001 From: Maxime Lalo Date: Mon, 27 Nov 2023 15:49:08 +0100 Subject: [PATCH] :sparkles: Clearing totp code after login/set password --- src/common/repositories/CustomersRepository.ts | 4 ++-- .../customer/CustomersService/CustomersService.ts | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/common/repositories/CustomersRepository.ts b/src/common/repositories/CustomersRepository.ts index 6ab46516..6844fddb 100644 --- a/src/common/repositories/CustomersRepository.ts +++ b/src/common/repositories/CustomersRepository.ts @@ -5,8 +5,8 @@ import { Customers, ECivility, ECustomerStatus, Prisma } from "@prisma/client"; import { Customer } from "le-coffre-resources/dist/SuperAdmin"; type IExcludedCustomerVars = { - totpCode?: string; - totpCodeExpire?: Date; + totpCode?: string | null; + totpCodeExpire?: Date | null; password?: string; }; @Service() diff --git a/src/services/customer/CustomersService/CustomersService.ts b/src/services/customer/CustomersService/CustomersService.ts index fe52345b..ccab039e 100644 --- a/src/services/customer/CustomersService/CustomersService.ts +++ b/src/services/customer/CustomersService/CustomersService.ts @@ -158,6 +158,16 @@ export default class CustomersService extends BaseService { const isPasswordValid = await this.authService.comparePassword(password, customer.password); if (!isPasswordValid) throw new InvalidPasswordError(); + await this.customerRepository.update( + customer.uid as string, + Customer.hydrate({ + ...customer, + }), + { + totpCode: null, + totpCodeExpire: null, + }, + ); // 6: Return the customer return customer; } @@ -173,6 +183,8 @@ export default class CustomersService extends BaseService { ...customer, }), { + totpCode: null, + totpCodeExpire: null, password, }, );