Skip to content

<UserButton />

<UserButton /> renders the current user’s avatar with a popover that surfaces “Manage account”, “Sign out”, a language switcher, and (when Organizations are enabled on the environment) an inline org-switcher. It’s the v1 component you drop into the corner of your app’s chrome.

Available from v1 of @authn.sh/sdk-react.

import { UserButton } from '@authn.sh/sdk-react';
export default function AppShell({ children }) {
return (
<div>
<nav>
<a href="/">Home</a>
<UserButton />
</nav>
{children}
</div>
);
}

When the user is signed out, the component renders nothing — you’ll typically render a <Link to="/sign-in"> next to it and let one of the two show at a time.

PropTypeDefaultDescription
afterSignOutUrlstringenvironment home_urlWhere to send the user after they click Sign out.
signInUrlstringenvironment sign-in URLWhere to send the user when they don’t have an active session (typically used in tandem with <SignedOut /> to bypass rendering the component itself).
userProfileUrlstring/userThe route the Manage account link points at — wire it to the page that hosts <UserProfile />.
userProfileMode'navigation' | 'modal''navigation'navigation opens userProfileUrl in the current tab. modal opens <UserProfile /> in an in-place modal dialog (useful when your app has no dedicated account page).
showNamebooleanfalseWhen true, renders the user’s name next to the avatar.
appearanceAppearancePer-render appearance override.
localizationLocalizationPer-render localization override.
defaultOpenbooleanfalseForces the popover open on mount. Useful for product tours / onboarding.

For a custom popover layout, the action rows are exposed:

  • <UserButton.MenuItems /> — full menu list customisation.
  • <UserButton.Action label="…" labelIcon={…} onClick={…} /> — slot a custom action.
  • <UserButton.Link label="…" labelIcon={…} href="…" /> — slot a custom link.
<UserButton>
<UserButton.MenuItems>
<UserButton.Action
label="Switch theme"
labelIcon={<MoonIcon />}
onClick={() => toggleTheme()}
/>
<UserButton.Link
label="Help"
labelIcon={<HelpIcon />}
href="/help"
/>
</UserButton.MenuItems>
</UserButton>

Custom items render after the bundled rows (Manage account, language picker, theme picker, Sign out).

When the environment has Organizations enabled, the popover includes an inline org list and a “Create organization” action. Switching organizations changes User.active_organization and refreshes the JWT with the new org claim. See <OrganizationSwitcher /> for a standalone variant when you want the org picker outside the <UserButton /> chrome.