Skip to content

Commit a17b118

Browse files
committed
feat(clerk-js,types): New updatePassword method for UserResource
This new method performs a PATCH request to `/v1/me/password` FAPI endpoint. + Marked the `password` property of `UpdateUserParams` as deprecated
1 parent b3d25b4 commit a17b118

3 files changed

Lines changed: 30 additions & 1 deletion

File tree

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import type {
1717
TOTPJSON,
1818
TOTPResource,
1919
UpdateUserParams,
20+
UpdateUserPasswordParams,
2021
UserJSON,
2122
UserResource,
2223
VerifyTOTPParams,
@@ -199,6 +200,13 @@ export class User extends BaseResource implements UserResource {
199200
});
200201
};
201202

203+
updatePassword = (params: UpdateUserPasswordParams): Promise<UserResource> => {
204+
return this._basePatch({
205+
body: params,
206+
path: `${this.path()}/password`,
207+
});
208+
};
209+
202210
getSessions = async (): Promise<SessionWithActivities[]> => {
203211
if (this.cachedSessionsWithActivities) {
204212
return this.cachedSessionsWithActivities;

packages/types/src/json.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ export interface UserJSON extends ClerkResourceJSON {
179179
external_accounts: ExternalAccountJSON[];
180180
organization_memberships: OrganizationMembershipJSON[];
181181
password_enabled: boolean;
182+
/**
183+
* @deprecated This will be removed in the next major version
184+
*/
182185
password: string;
183186
profile_image_id: string;
184187
first_name: string;

packages/types/src/user.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export interface UserResource extends ClerkResource {
6464
createdAt: Date | null;
6565

6666
update: (params: UpdateUserParams) => Promise<UserResource>;
67+
updatePassword: (params: UpdateUserPasswordParams) => Promise<UserResource>;
6768
createEmailAddress: (params: CreateEmailAddressParams) => Promise<EmailAddressResource>;
6869
createPhoneNumber: (params: CreatePhoneNumberParams) => Promise<PhoneNumberResource>;
6970
createWeb3Wallet: (params: CreateWeb3WalletParams) => Promise<Web3WalletResource>;
@@ -75,9 +76,13 @@ export interface UserResource extends ClerkResource {
7576
verifyTOTP: (params: VerifyTOTPParams) => Promise<TOTPResource>;
7677
disableTOTP: () => Promise<DeletedObjectResource>;
7778
createBackupCode: () => Promise<BackupCodeResource>;
79+
7880
get verifiedExternalAccounts(): ExternalAccountResource[];
81+
7982
get unverifiedExternalAccounts(): ExternalAccountResource[];
83+
8084
get hasVerifiedEmailAddress(): boolean;
85+
8186
get hasVerifiedPhoneNumber(): boolean;
8287
}
8388

@@ -108,4 +113,17 @@ type UpdateUserJSON = Pick<
108113
| 'unsafe_metadata'
109114
>;
110115

111-
export type UpdateUserParams = Partial<SnakeToCamel<UpdateUserJSON>>;
116+
export type UpdateUserParams = Partial<
117+
SnakeToCamel<UpdateUserJSON> & {
118+
/**
119+
* @deprecated This will be removed in the next major version. Please use `updatePassword(params)` instead
120+
*/
121+
password: string;
122+
}
123+
>;
124+
125+
export type UpdateUserPasswordParams = {
126+
newPassword: string;
127+
currentPassword?: string;
128+
signOutOfOtherSessions?: boolean;
129+
};

0 commit comments

Comments
 (0)