Skip to content

Commit cc82b13

Browse files
committed
feat(clerk-js): Add removePassword in User resource
1 parent 51055ae commit cc82b13

3 files changed

Lines changed: 30 additions & 6 deletions

File tree

packages/clerk-js/src/core/resources/User.test.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,7 @@ describe('User', () => {
272272
// @ts-ignore
273273
BaseResource._fetch = jest.fn().mockReturnValue(Promise.resolve({ response: {} }));
274274

275-
const user = new User({
276-
email_addresses: [],
277-
phone_numbers: [],
278-
web3_wallets: [],
279-
external_accounts: [],
280-
} as unknown as UserJSON);
275+
const user = new User({} as unknown as UserJSON);
281276
const params = {
282277
currentPassword: 'current-password',
283278
newPassword: 'new-password',
@@ -291,4 +286,22 @@ describe('User', () => {
291286
body: params,
292287
});
293288
});
289+
290+
it('.removePassword triggers a request to remove password', async () => {
291+
// @ts-ignore
292+
BaseResource._fetch = jest.fn().mockReturnValue(Promise.resolve({ response: {} }));
293+
294+
const user = new User({} as unknown as UserJSON);
295+
const params = {
296+
currentPassword: 'current-password',
297+
};
298+
await user.removePassword(params);
299+
300+
// @ts-ignore
301+
expect(BaseResource._fetch).toHaveBeenCalledWith({
302+
method: 'POST',
303+
path: '/me/remove_password',
304+
body: params,
305+
});
306+
});
294307
});

packages/clerk-js/src/core/resources/User.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
ImageResource,
1414
OrganizationMembershipResource,
1515
PhoneNumberResource,
16+
RemoveUserPasswordParams,
1617
SetProfileImageParams,
1718
TOTPJSON,
1819
TOTPResource,
@@ -207,6 +208,13 @@ export class User extends BaseResource implements UserResource {
207208
});
208209
};
209210

211+
removePassword = (params: RemoveUserPasswordParams): Promise<UserResource> => {
212+
return this._basePost({
213+
body: params,
214+
path: `${this.path()}/remove_password`,
215+
});
216+
};
217+
210218
getSessions = async (): Promise<SessionWithActivities[]> => {
211219
if (this.cachedSessionsWithActivities) {
212220
return this.cachedSessionsWithActivities;

packages/types/src/user.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ export interface UserResource extends ClerkResource {
6565

6666
update: (params: UpdateUserParams) => Promise<UserResource>;
6767
updatePassword: (params: UpdateUserPasswordParams) => Promise<UserResource>;
68+
removePassword: (params: RemoveUserPasswordParams) => Promise<UserResource>;
6869
createEmailAddress: (params: CreateEmailAddressParams) => Promise<EmailAddressResource>;
6970
createPhoneNumber: (params: CreatePhoneNumberParams) => Promise<PhoneNumberResource>;
7071
createWeb3Wallet: (params: CreateWeb3WalletParams) => Promise<Web3WalletResource>;
@@ -127,3 +128,5 @@ export type UpdateUserPasswordParams = {
127128
currentPassword?: string;
128129
signOutOfOtherSessions?: boolean;
129130
};
131+
132+
export type RemoveUserPasswordParams = Pick<UpdateUserPasswordParams, 'currentPassword'>;

0 commit comments

Comments
 (0)