You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/guides/users/extending.mdx
+9-4Lines changed: 9 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -61,9 +61,14 @@ See the following examples to see how to set unsafe metadata on the frontend (cl
61
61
62
62
<Tabsitems={["Client-side", "Server-side"]}>
63
63
<Tab>
64
+
Use the [`User.updateMetadata()`](/docs/reference/objects/user#update-metadata) method to update unsafe metadata from the frontend. The provided value is **deep-merged** with the existing `unsafeMetadata`, and any key set to `null` is removed.
65
+
66
+
> [!TIP]
67
+
> You can also use [`User.update()`](/docs/reference/objects/user#update) to update unsafe metadata, but it **fully replaces** the value instead of merging. Use `User.updateMetadata()` when you need to change specific keys.
68
+
64
69
<Tabsitems={["React-based SDKs", "JavaScript"]}>
65
70
<Tab>
66
-
For React-based SDKs, such as Next.js, use the [`useUser()`](/docs/reference/hooks/use-user) hook to update unsafe metadata.
71
+
For React-based SDKs, such as Next.js, use the [`useUser()`](/docs/reference/hooks/use-user) hook to access the `User` object and call the `updateMetadata()` method.
67
72
68
73
```tsx {{ filename: 'page.tsx' }}
69
74
exportdefaultfunction Page() {
@@ -76,7 +81,7 @@ See the following examples to see how to set unsafe metadata on the frontend (cl
76
81
77
82
<button
78
83
onClick={() => {
79
-
user?.update({
84
+
user?.updateMetadata({
80
85
unsafeMetadata: { birthday },
81
86
})
82
87
}}
@@ -90,7 +95,7 @@ See the following examples to see how to set unsafe metadata on the frontend (cl
90
95
</Tab>
91
96
92
97
<Tab>
93
-
When using the JavaScript SDK, use the [`User.update()`](/docs/reference/objects/user#update) method to update unsafe metadata.
98
+
When using the JavaScript SDK, use the [`Clerk`](/docs/reference/objects/clerk) object to access the `User` object and call the `updateMetadata()` method.
94
99
95
100
```js {{ filename: 'main.js' }}
96
101
import { Clerk } from'@clerk/clerk-js'
@@ -103,7 +108,7 @@ See the following examples to see how to set unsafe metadata on the frontend (cl
MetadatathatcanbereadandsetfromtheFrontendAPI. Onecommonusecaseforthisattributeistoimplementcustomfieldsthatwillbeattachedtothe`User`object. Using`update()`toupdatethisvaluefullyreplacestheexistingvalue. Toperformamerge, use [`updateMetadata()`](#update-metadata) instead.
779
+
</Properties>
780
+
781
+
### `updateMetadata()`
782
+
783
+
Updatestheuser's `unsafeMetadata` using deep-merge semantics. Unlike [`update()`](#update), which fully replaces `unsafeMetadata`, this method merges the provided value with the existing `unsafeMetadata`. Top-level and nested keys are merged, and any key set to `null` is removed. Only `unsafeMetadata` is writable from the frontend; `publicMetadata` and `privateMetadata` can only be set from the [Backend API](/docs/reference/backend-api){{ target: '_blank' }}.
784
+
785
+
```ts
786
+
function updateMetadata(params: UpdateUserMetadataParams): Promise<User>
0 commit comments