Skip to content

Commit

Permalink
Add user payment & webauth credentials delete helper in modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikearaya committed Dec 20, 2024
1 parent 21116b8 commit 5e0768b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ export const configurePaymentCredentialsModule = (
const paymentCredentials = await PaymentCredentials.findOneAndDelete(selector, {});
return paymentCredentials;
},
removeUserCredentials: async (userId: string): Promise<number> => {
const { deletedCount } = await PaymentCredentials.deleteMany({ userId }, {});
return deletedCount;
},
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface UsersWebAuthnModule {
extensionOptions?: any,
) => Promise<any>;
verifyCredentialRequest: (userPublicKeys: any[], username: string, credentials: any) => Promise<any>;
deleteUserCredentials: (username: string) => Promise<number>;
}

const logger = createLogger('unchained:core-users');
Expand Down Expand Up @@ -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;
},
};
};
2 changes: 2 additions & 0 deletions packages/core/src/services/deleteUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down

0 comments on commit 5e0768b

Please sign in to comment.