Clearing totp code after login/set password

This commit is contained in:
Maxime Lalo 2023-11-27 15:49:08 +01:00
parent 6c00162544
commit cdbb3e3257
2 changed files with 14 additions and 2 deletions

View File

@ -5,8 +5,8 @@ import { Customers, ECivility, ECustomerStatus, Prisma } from "@prisma/client";
import { Customer } from "le-coffre-resources/dist/SuperAdmin"; import { Customer } from "le-coffre-resources/dist/SuperAdmin";
type IExcludedCustomerVars = { type IExcludedCustomerVars = {
totpCode?: string; totpCode?: string | null;
totpCodeExpire?: Date; totpCodeExpire?: Date | null;
password?: string; password?: string;
}; };
@Service() @Service()

View File

@ -158,6 +158,16 @@ export default class CustomersService extends BaseService {
const isPasswordValid = await this.authService.comparePassword(password, customer.password); const isPasswordValid = await this.authService.comparePassword(password, customer.password);
if (!isPasswordValid) throw new InvalidPasswordError(); if (!isPasswordValid) throw new InvalidPasswordError();
await this.customerRepository.update(
customer.uid as string,
Customer.hydrate<Customer>({
...customer,
}),
{
totpCode: null,
totpCodeExpire: null,
},
);
// 6: Return the customer // 6: Return the customer
return customer; return customer;
} }
@ -173,6 +183,8 @@ export default class CustomersService extends BaseService {
...customer, ...customer,
}), }),
{ {
totpCode: null,
totpCodeExpire: null,
password, password,
}, },
); );