From 5e0768b0447e9d147c80e00c3921c8fadf52a5dc Mon Sep 17 00:00:00 2001 From: Mikael Araya Date: Thu, 19 Dec 2024 14:59:24 +0300 Subject: [PATCH] Add user payment & webauth credentials delete helper in modules --- .../src/module/configurePaymentCredentialsModule.ts | 4 ++++ .../core-users/src/module/configureUsersWebAuthnModule.ts | 7 +++++++ packages/core/src/services/deleteUser.ts | 2 ++ 3 files changed, 13 insertions(+) diff --git a/packages/core-payment/src/module/configurePaymentCredentialsModule.ts b/packages/core-payment/src/module/configurePaymentCredentialsModule.ts index 326783de51..f7dd408bdc 100644 --- a/packages/core-payment/src/module/configurePaymentCredentialsModule.ts +++ b/packages/core-payment/src/module/configurePaymentCredentialsModule.ts @@ -128,6 +128,10 @@ export const configurePaymentCredentialsModule = ( const paymentCredentials = await PaymentCredentials.findOneAndDelete(selector, {}); return paymentCredentials; }, + removeUserCredentials: async (userId: string): Promise => { + const { deletedCount } = await PaymentCredentials.deleteMany({ userId }, {}); + return deletedCount; + }, }; }; diff --git a/packages/core-users/src/module/configureUsersWebAuthnModule.ts b/packages/core-users/src/module/configureUsersWebAuthnModule.ts index cae2f4110c..758aa0423e 100644 --- a/packages/core-users/src/module/configureUsersWebAuthnModule.ts +++ b/packages/core-users/src/module/configureUsersWebAuthnModule.ts @@ -19,6 +19,7 @@ export interface UsersWebAuthnModule { extensionOptions?: any, ) => Promise; verifyCredentialRequest: (userPublicKeys: any[], username: string, credentials: any) => Promise; + deleteUserCredentials: (username: string) => Promise; } const logger = createLogger('unchained:core-users'); @@ -231,5 +232,11 @@ export const configureUsersWebAuthnModule = async ({ const loginResult = await f2l.assertionResult(assertionResponse, assertionExpectations); return { userHandle: loginResult?.authnrData?.get('userHandle') }; }, + deleteUserCredentials: async (username: string) => { + const { deletedCount } = await WebAuthnCredentialsCreationRequests.deleteMany({ + username, + }); + return deletedCount; + }, }; }; diff --git a/packages/core/src/services/deleteUser.ts b/packages/core/src/services/deleteUser.ts index 0c0974b6a5..f6fb8a5f5b 100644 --- a/packages/core/src/services/deleteUser.ts +++ b/packages/core/src/services/deleteUser.ts @@ -8,6 +8,8 @@ export async function deleteUserService(this: Modules, { userId }: { userId: str await this.bookmarks.deleteByUserId(userId); await this.quotations.deleteRequestedUserQuotations(userId); await this.enrollments.deleteInactiveUserEnrollments(userId); + await this.payment.paymentCredentials.removeUserCredentials(userId); + await this.users.webAuthn.deleteUserCredentials(user.username); const carts = await this.orders.findOrders({ userId, status: null });