ReactUserButton

A fully customizable authenticated user avatar button with dropdown menu, session-based user detection, responsive positioning, and built-in logout handling.

Usage

Wrap the component inside AuthixProvider and pass your logout handler.

Jsx
1import { AuthixProvider, ReactUserButton } from "@neuctra/authix";
2import { authix } from "./neuctraAuthixInit";
3
4export default function App() {
5  const handleLogout = async () => {
6    await authix.logoutUser();
7  };
8
9  return (
10    <AuthixProvider authix={authix}>
11      <div className="flex justify-end p-6">
12        <ReactUserButton
13          onLogout={handleLogout}
14          menuItems={[
15            {
16              label: "Profile",
17              icon: "👤",
18              href: "/profile",
19            },
20            {
21              label: "Settings",
22              icon: "⚙️",
23              href: "/settings",
24            },
25            { type: "divider" },
26            {
27              label: "Support",
28              icon: "💬",
29              onClick: () => console.log("Support clicked"),
30            },
31          ]}
32        />
33      </div>
34    </AuthixProvider>
35  );
36};

Props

Configuration options for customizing the user button.

PropTypeDefaultDescription
menuItemsMenuItem[][]Custom dropdown menu items (links, buttons, dividers).
darkModebooleantrueEnables dark theme styling.
onLogout() => voidCalled when user clicks logout button.
propUserUserInfo | nullnullManually provide user data (overrides session).
logoutLabelstring"Sign Out"Label for logout button.
wrapperClassNamestringCustom wrapper styling.
avatarClassNamestringCustom avatar button styling.
dropdownClassNamestringCustom dropdown container styling.
menuItemClassNamestringCustom menu item styling.
logoutButtonClassNamestringCustom logout button styling.

Features

  • Auto user detection from Neuctra Authix session
  • Supports manual user override via propUser
  • Responsive avatar sizing (mobile + desktop)
  • Smart dropdown positioning (viewport aware)
  • Click-outside, ESC key, and scroll auto-close
  • Custom menu items (links, buttons, dividers)
  • Dark mode support

MenuItem Type

Ts
1type MenuItem = {
2  label: string;
3  href?: string;
4  icon?: React.ReactNode;
5  onClick?: () => void;
6  type?: "link" | "button" | "divider";
7};

SDK Methods Used

authix.checkUserSession()authix.logoutUser()

The component automatically resolves the user session on mount and updates UI accordingly. Logout is fully controlled via the providedonLogout handler.