Skip to main content
Docs

Add custom items and links to the <UserButton /> component

The <UserButton /> component supports custom menu items, allowing the incorporation of app-specific settings or additional functionality.

There are two types of custom menu items available:

You can also reorder default items and conditionally render menu items.

<UserButton.Action>

<UserButton.Action /> allows you to add actions to the <UserButton /> component, like opening a chat or triggering a modal.

Props

<UserButton.Action /> accepts the following props:

  • Name
    label
    Type
    string
    Description

    The name that will be displayed in the menu of the user button.

  • Name
    labelIcon
    Type
    React.ReactElement
    Description

    An icon displayed next to the label in the menu.

  • Name
    open?
    Type
    string
    Description

    The path segment that will be used to open the user profile modal to a specific page.

  • Name
    onClick?
    Type
    void
    Description

    A function to be called when the menu item is clicked.

Examples

Add an action

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.

/app/page.tsx
'use client'

import { UserButton } from '@clerk/nextjs'

const DotIcon = () => {
  return (
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="currentColor">
      <path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512z" />
    </svg>
  )
}

export default function Home() {
  return (
    <header>
      <UserButton>
        <UserButton.MenuItems>
          <UserButton.Action
            label="Open chat"
            labelIcon={<DotIcon />}
            onClick={() => alert('init chat')}
          />
        </UserButton.MenuItems>
      </UserButton>
    </header>
  )
}

Add an action and a custom page

The following example adds an "Open chat" action to the <UserButton /> component, as well as a custom page titled "Help". When a user selects the <UserButton />, there will be "Open chat" and "Help" menu items.

/app/page.tsx
'use client'

import { UserButton } from '@clerk/nextjs'

const DotIcon = () => {
  return (
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="currentColor">
      <path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512z" />
    </svg>
  )
}

export default function Home() {
  return (
    <header>
      <UserButton>
        <UserButton.MenuItems>
          <UserButton.Action label="Help" labelIcon={<DotIcon />} open="help" />
        </UserButton.MenuItems>

        <UserButton.UserProfilePage label="Help" labelIcon={<DotIcon />} url="help">
          <div>
            <h1>Help Page</h1>
            <p>This is the custom help page</p>
          </div>
        </UserButton.UserProfilePage>
      </UserButton>
    </header>
  )
}

<UserButton.Link /> allows you to add links to the <UserButton /> component, like custom pages or external URLs.

Props

<UserButton.Link /> accept the following props, all of which are required:

  • Name
    label
    Type
    string
    Description

    The name that will be displayed in the menu of the user button.

  • Name
    labelIcon
    Type
    React.ReactElement
    Description

    An icon displayed next to the label in the menu.

  • Name
    href
    Type
    string
    Description

    The path segment that will be used to navigate to the custom page.

Example

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.

/app/page.tsx
'use client'

import { UserButton } from '@clerk/nextjs'

const DotIcon = () => {
  return (
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="currentColor">
      <path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512z" />
    </svg>
  )
}

export default function Home() {
  return (
    <header>
      <UserButton>
        <UserButton.MenuItems>
          <UserButton.Link
            label="Create organization"
            labelIcon={<DotIcon />}
            href="/create-organization"
          />
        </UserButton.MenuItems>
      </UserButton>
    </header>
  )
}

Reorder default items

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.

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.

/app/page.tsx
'use client'

import { UserButton } from '@clerk/nextjs'

const DotIcon = () => {
  return (
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="currentColor">
      <path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512z" />
    </svg>
  )
}

export default function Home() {
  return (
    <header>
      <UserButton>
        <UserButton.MenuItems>
          <UserButton.Action label="signOut" />
          <UserButton.Link
            label="Create organization"
            labelIcon={<DotIcon />}
            href="/create-organization"
          />
          <UserButton.Action label="manageAccount" />
        </UserButton.MenuItems>
      </UserButton>
    </header>
  )
}

Conditionally render menu items

To conditionally render menu items based on a user's role or custom permissions, you can use the has() helper function.

In the following example, the "Create organization" menu item will only render if the current user has the org:app:admin permission.

/app/page.tsx
'use client'

import { UserButton, useAuth } from '@clerk/nextjs'

const DotIcon = () => {
  return (
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" fill="currentColor">
      <path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512z" />
    </svg>
  )
}

export default function Home() {
  const { has, isLoaded } = useAuth()

  if (!isLoaded) {
    return <span>Loading...</span>
  }

  const isAdmin = has({ permission: 'org:app:admin' })

  return (
    <header>
      <UserButton>
        {isAdmin && (
          <UserButton.MenuItems>
            <UserButton.Link
              label="Create organization"
              labelIcon={<DotIcon />}
              href="/create-organization"
            />
          </UserButton.MenuItems>
        )}
      </UserButton>
    </header>
  )
}

Feedback

What did you think of this content?

Last updated on