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.
The <UserButton /> component must be wrapped in a <UserButton.MenuItems /> component to render the custom action.
The following example demonstrates how to add an action to the <UserButton /> component.
Next.js
Astro
JavaScript
In Astro components, props are converted to strings, so you can't use an onClick handler to handle click events. Instead, you can set an arbitrary prop, set up a custom event listener that will check for the value passed to that prop, and then execute a desired action based on that value.
For example, clickIdentifier is the arbitrary prop being used to identify the click event. Two <UserButton.Action /> components are added to the menu, each with a different clickIdentifier prop. When the menu item is clicked, the custom event listener will check for the value passed to the clickIdentifier prop, either "open_chat" or "open_cart", and then execute an action based on that value.
To add custom menu items to the <UserButton /> component using the JavaScript SDK, pass the customMenuItems property to the mountUserButton() method, as shown in the following example:
The following example demonstrates how to add an action, as well as a custom page, to the <UserButton /> component.
Next.js
Astro
In the following example, the <UserButton.Action /> component is used to add a "Help" menu item to the <UserButton /> component. The open prop is set to "help" to open the /help page when the menu item is selected.
The <UserButton.UserProfilePage /> component is used to render the /help page, and because its configured as a user profile page, the <UserProfile /> modal will be opened with the custom "Help" menu item. Read more about custom pages.
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.
The <UserButton /> component must be wrapped in a <UserButton.MenuItems /> component to render the custom link.
The following example demonstrates how to add a link to the <UserButton /> component.
Next.js
Astro
JavaScript
To add custom menu items to the <UserButton /> component using the JavaScript SDK, pass the customMenuItems property to the mountUserButton() method, as shown in the following example:
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:
Next.js
Astro
With the above example, the <UserButton /> menu items will be in the following order: