diff --git a/packages/core-payment/src/module/configurePaymentCredentialsModule.ts b/packages/core-payment/src/module/configurePaymentCredentialsModule.ts index 326783de5..f7dd408bd 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 cae2f4110..758aa0423 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 0c0974b6a..f6fb8a5f5 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 });