Skip to content

Commit 27effd8

Browse files
Add update user password method (#794)
## Description Adds the update user password method for the user management API ## Documentation Does this require changes to the WorkOS Docs? E.g. the [API Reference](https://workos.com/docs/reference) or code snippets need updates. ``` [ ] Yes ``` If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.
1 parent c99d908 commit 27effd8

File tree

6 files changed

+46
-0
lines changed

6 files changed

+46
-0
lines changed

src/users/interfaces/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ export * from './remove-user-from-organization-options.interface';
1111
export * from './revoke-session-options.interface';
1212
export * from './user.interface';
1313
export * from './verify-session.interface';
14+
export * from './update-user-password-options.interface';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export interface UpdateUserPasswordOptions {
2+
userId: string;
3+
password: string;
4+
}
5+
6+
export interface SerializedUpdateUserPasswordOptions {
7+
password: string;
8+
}

src/users/serializers/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export * from './create-password-reset-challenge.serializer';
77
export * from './create-user-options.serializer';
88
export * from './revoke-session-options.serializer';
99
export * from './session.serializer';
10+
export * from './update-user-password-options.serializer';
1011
export * from './user.serializer';
1112
export * from './verify-session.serializer';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {
2+
SerializedUpdateUserPasswordOptions,
3+
UpdateUserPasswordOptions,
4+
} from '../interfaces';
5+
6+
export const serializeUpdateUserPasswordOptions = (
7+
options: UpdateUserPasswordOptions,
8+
): SerializedUpdateUserPasswordOptions => ({
9+
password: options.password,
10+
});

src/users/users.spec.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,4 +328,19 @@ describe('UserManagement', () => {
328328
});
329329
});
330330
});
331+
332+
describe('updateUserPassword', () => {
333+
it('sends a updateUserPassword request', async () => {
334+
mock.onPut(`/users/${userId}/password`).reply(200, userFixture);
335+
const resp = await workos.users.updateUserPassword({
336+
userId,
337+
password: 'secure',
338+
});
339+
340+
expect(mock.history.put[0].url).toEqual(`/users/${userId}/password`);
341+
expect(resp).toMatchObject({
342+
343+
});
344+
});
345+
});
331346
});

src/users/users.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
SerializedCreateUserOptions,
2626
SerializedRevokeSessionOptions,
2727
SerializedVerifySessionOptions,
28+
UpdateUserPasswordOptions,
2829
User,
2930
UserResponse,
3031
VerifySessionOptions,
@@ -44,6 +45,7 @@ import {
4445
serializeCreatePasswordResetChallengeOptions,
4546
serializeCreateUserOptions,
4647
serializeRevokeSessionOptions,
48+
serializeUpdateUserPasswordOptions,
4749
serializeVerifySessionOptions,
4850
} from './serializers';
4951
import { deserializeList } from '../common/serializers';
@@ -217,4 +219,13 @@ export class Users {
217219

218220
return deserializeUser(data);
219221
}
222+
223+
async updateUserPassword(payload: UpdateUserPasswordOptions): Promise<User> {
224+
const { data } = await this.workos.put<UserResponse>(
225+
`/users/${payload.userId}/password`,
226+
serializeUpdateUserPasswordOptions(payload),
227+
);
228+
229+
return deserializeUser(data);
230+
}
220231
}

0 commit comments

Comments
 (0)