Skip to content

Commit bdec0ff

Browse files
committed
unsafe_metadata required on UpdateUserMetadataParams
1 parent 62a2c95 commit bdec0ff

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -745,18 +745,20 @@ describe('User', () => {
745745
});
746746
});
747747

748-
it('.updateMetadata omits unsafe_metadata when not provided', async () => {
748+
it('.updateMetadata sends an explicit null patch when a key is being removed', async () => {
749749
// @ts-ignore
750750
BaseResource._fetch = vi.fn().mockReturnValue(Promise.resolve({ response: {} }));
751751

752752
const user = new User({} as unknown as UserJSON);
753-
await user.updateMetadata({});
753+
await user.updateMetadata({ unsafeMetadata: { theme: null as unknown as undefined } });
754754

755755
// @ts-ignore
756756
expect(BaseResource._fetch).toHaveBeenCalledWith({
757757
method: 'PATCH',
758758
path: '/me/metadata',
759-
body: {},
759+
body: {
760+
unsafeMetadata: JSON.stringify({ theme: null }),
761+
},
760762
});
761763
});
762764
});

packages/shared/src/types/user.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ export type UpdateUserParams = Partial<SnakeToCamel<UpdateUserJSON>>;
190190

191191
/**
192192
* Parameters for {@link UserResource.updateMetadata}. Only `unsafeMetadata`
193-
* is end-user-writable on the Frontend API. The submitted value is deep-merged
194-
* with the existing `unsafeMetadata`; keys at any level whose value is `null`
195-
* are removed.
193+
* is end-user-writable on the Frontend API and the field is required: the
194+
* submitted value is deep-merged with the existing `unsafeMetadata`, and keys
195+
* at any level whose value is `null` are removed.
196196
*/
197197
export type UpdateUserMetadataParams = {
198-
unsafeMetadata?: UserUnsafeMetadata;
198+
unsafeMetadata: UserUnsafeMetadata;
199199
};
200200

201201
export type UpdateUserPasswordParams = {

0 commit comments

Comments
 (0)