Skip to Content
Clerk logo

Clerk Docs

Ctrl + K
Go to clerkstage.dev

<UserButton />

User Button Example

The <UserButton /> component is used to render the familiar user button UI popularized by Google.

Clerk is the only provider with multi-session support, allowing users to sign into multiple accounts at once and switch between them. For multisession apps, the <UserButton /> automatically supports instant account switching, without the need of a full page reload. For more information, you can check out the Multi-session applications guide.

Usage

In this example, <UserButton /> is mounted inside a header component, which is a common pattern on many websites and applications. When the user is signed in, they will see their avatar and be able to open the popup menu.

layout.[jsx/tsx]
import { ClerkProvider, SignedIn, SignedOut, SignInButton, UserButton, } from "@clerk/nextjs"; function Header() { return ( <header style={{ display: "flex", justifyContent: "space-between", padding: 20 }}> <h1>My App</h1> <SignedIn> {/* Mount the UserButton component */} <UserButton /> </SignedIn> <SignedOut> {/* Signed out users get sign in button */} <SignInButton/> </SignedOut> </header> ); } export default function RootLayout({ children }: { children: React.ReactNode }) { return ( <html lang="en"> <ClerkProvider> <Header /> {children} </ClerkProvider> </html> ); }
userButtonExample.[jsx/tsx]
import { ClerkProvider, SignedIn, SignedOut, SignInButton, UserButton, } from "@clerk/nextjs"; function Header() { return ( <header style={{ display: "flex", justifyContent: "space-between", padding: 20 }}> <h1>My App</h1> <SignedIn> {/* Mount the UserButton component */} <UserButton /> </SignedIn> <SignedOut> {/* Signed out users get sign in button */} <SignInButton/> </SignedOut> </header> ); } function MyApp({ pageProps }) { return ( <ClerkProvider {...pageProps}> <Header /> </ClerkProvider> ); } export default MyApp;

Properties

All props below are optional.

NameTypeDescription
appearanceAppearance | undefinedOptional object to style your components. Will only affect Clerk Components and not Account Portal pages.
showNamebooleanControls if the user name is displayed next to the user image button.
signInUrlstringThe full URL or path to navigate to when the "Add another account" button is clicked.
userProfileMode'modal' | 'navigation'Controls whether clicking the "Manage your account" button will cause the <UserProfile /> component to open as a modal, or if the browser will navigate to the userProfileUrl where <UserProfile /> is mounted as a page.
Defaults to: 'modal'.
userProfileUrlstringThe full URL or path leading to the user management interface.
afterSignOutUrlstringThe full URL or path to navigate to after a signing out from all accounts (applies to both single-session and multi-session apps).
afterMultiSessionSingleSignOutUrlstringThe full URL or path to navigate to after a signing out from currently active account (multisession apps).
afterSwitchSessionUrlstringThe full URL or path to navigate to after a successful account change (multi-session apps).
defaultOpenbooleanControls whether the <UserButton /> should open by default during the first render.
userProfilePropsobjectSpecify options for the underlying <UserProfile /> component. e.g. {additionalOAuthScopes: {google: ['foo', 'bar'], github: ['qux']}}.

Customization

To learn about how to customize Clerk components, see the customization documentation.

What did you think of this content?

Clerk © 2024