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
@@ -5,21 +5,16 @@ description: Learn how to add custom items and include external links within the
5
5
6
6
The [`<UserButton />`](/docs/components/user/user-button) component supports _custom_ menu items, allowing the incorporation of app-specific settings or additional functionality.
7
7
8
-
To add a custom menu item to the `<UserButton />` component, use the `<UserButton.MenuItems />` component.
9
-
10
8
There are two types of custom menu items available:
11
9
12
-
-`<UserButton.Action>` - A menu item that triggers an action when clicked.
13
-
-`<UserButton.Link>` - A menu item that navigates to a page when clicked.
10
+
-[`<UserButton.Action>`](#user-button-action) - A menu item that triggers an action when clicked.
11
+
-[`<UserButton.Link>`](#user-button-link) - A menu item that navigates to a page when clicked.
14
12
15
-
> [!IMPORTANT]
16
-
> If your app is rendered with [React Server Components](https://react.dev/reference/rsc/server-components) by default, you'll need to add the [`use client` directive](https://react.dev/reference/rsc/use-client) when using `<UserButton />`.
13
+
You can also [reorder default items](#reorder-default-items) and [conditionally render menu items](#conditionally-render-menu-items).
17
14
18
15
## `<UserButton.Action>`
19
16
20
-
Custom actions can be rendered inside the `<UserButton />` component using the `<UserButton.Action />` component. This component is useful for adding actions like opening a chat or triggering a modal.
21
-
22
-
The `<UserButton />` component must be wrapped in a `<UserButton.MenuItems />` component to render the custom action.
17
+
`<UserButton.Action />` allows you to add actions to the `<UserButton />` component, like opening a chat or triggering a modal.
23
18
24
19
### Props
25
20
@@ -53,11 +48,13 @@ The `<UserButton />` component must be wrapped in a `<UserButton.MenuItems />` c
53
48
A function to be called when the menu item is clicked.
54
49
</Properties>
55
50
56
-
### Example
51
+
### Examples
57
52
58
-
The following example demonstrates how to add an action to the `<UserButton />` component.
53
+
#### Add an action
59
54
60
-
<Tabsitems={["Next.js", "Astro", "JavaScript"]}>
55
+
The following example adds an "Open chat" action to the `<UserButton />` component. When a user selects the `<UserButton />`, there will be an "Open chat" menu item.
The following example demonstrates how to add an action, as well as a [custom page](/docs/customization/user-profile), to the `<UserButton />` component.
202
+
#### Add an action and a custom page
203
+
204
+
The following example adds an "Open chat" action to the `<UserButton />` component, as well as a [custom page](/docs/customization/user-profile) titled "Help". When a user selects the `<UserButton />`, there will be "Open chat" and "Help" menu items.
178
205
179
-
<Tabsitems={["Next.js", "Astro"]}>
206
+
<Tabsitems={["Next.js", "Astro", "Vue"]}>
180
207
<Tab>
181
208
```tsx filename="/app/page.tsx"
182
209
'use client'
@@ -255,13 +282,47 @@ The following example demonstrates how to add an action, as well as a [custom pa
Custom links can be rendered inside the `<UserButton />` component using the `<UserButton.Link />` component. This component is useful for adding links to custom pages or external URLs.
263
-
264
-
The `<UserButton />` component must be wrapped in a `<UserButton.MenuItems />` component to render the custom link.
325
+
`<UserButton.Link />` allows you to add links to the `<UserButton />` component, like custom pages or external URLs.
265
326
266
327
### Props
267
328
@@ -290,9 +351,9 @@ The `<UserButton />` component must be wrapped in a `<UserButton.MenuItems />` c
290
351
291
352
### Example
292
353
293
-
The following example demonstrates how to add a link to the `<UserButton />` component.
354
+
The following example adds a "Create organization" link to the `<UserButton />` component. When a user selects the `<UserButton />`, there will be a "Create organization" menu item.
The `<UserButton />` component includes two default menu items: `Manage account` and `Sign out`. You can reorder these default items by setting the `label` prop to `'manageAccount'` or `'signOut'`. This will target the existing default item and allow you to rearrange it, as shown in the following example:
472
+
The `<UserButton />` component includes two default menu items: `Manage account` and `Sign out`, in that order. You can reorder these default items by setting the `label` prop to `'manageAccount'` or `'signOut'`. This will target the existing default item and allow you to rearrange it.
473
+
474
+
In the following example, the "Sign out" menu item is moved to the top of the menu, a custom "Create organization" link is added as the second menu item, and the "Manage account" menu item is moved to the bottom of the menu.
388
475
389
-
<Tabsitems={["Next.js", "Astro"]}>
476
+
<Tabsitems={["Next.js", "Astro", "Vue"]}>
390
477
<Tab>
391
478
```tsx filename="/app/page.tsx"
392
479
'use client'
@@ -447,19 +534,41 @@ The `<UserButton />` component includes two default menu items: `Manage account`
447
534
</header>
448
535
```
449
536
</Tab>
450
-
</Tabs>
451
537
452
-
With the above example, the `<UserButton />` menu items will be in the following order:
To conditionally render menu items based on a user's role or custom permissions, you can use the [`has()`](/docs/references/backend/types/auth-object#has) helper function:
567
+
To conditionally render menu items based on a user's role or custom permissions, you can use the [`has()`](/docs/references/backend/types/auth-object#has) helper function.
568
+
569
+
In the following example, the "Create organization" menu item will only render if the current user has the `org:app:admin` permission.
461
570
462
-
<Tabsitems={["Next.js", "Astro"]}>
571
+
<Tabsitems={["Next.js", "Astro", "Vue"]}>
463
572
<Tab>
464
573
```tsx filename="/app/page.tsx"
465
574
'use client'
@@ -534,6 +643,33 @@ To conditionally render menu items based on a user's role or custom permissions,
534
643
</header>
535
644
```
536
645
</Tab>
537
-
</Tabs>
538
646
539
-
With the above example, the "Create organization" menu item will only render if the current user has the `org:app:admin` permission.
0 commit comments