Skip to main content

Overview

The UserCenter component is a ready-to-use dropdown menu that displays user information and provides authentication controls. It automatically adapts based on authentication state, showing either a sign-in button or user profile menu.

Installation

Basic Usage

Props

className
string
Additional CSS classes to apply to the avatar element. ```tsx
signoutCallbackUrl
string
URL to redirect to after sign-out. Defaults to current page. ```tsx
additionalPages
AdditionalPage[]
default:"[]"
Additional menu items to show in the dropdown before the sign-out button.

States

Loading State

While authentication state is loading, displays a pulsing skeleton:

Authenticated State

When a user is signed in, shows:
  • User avatar (if available) or initials
  • Dropdown menu with:
    • User name and email
    • Additional custom pages (if configured)
    • Sign out button

Unauthenticated State

When no user is signed in, shows:
  • Generic user icon
  • Dropdown menu with sign-in button

Examples

Basic Implementation

With Custom Pages

Custom Styling

Local Sign-Out Only

User Data Display

The component automatically displays:
  • User Avatar: If user.avatar exists, shows the avatar image
  • User Initials: If no avatar, generates initials from user.name
  • User Name: Displays as the main label in the dropdown
  • User Email: Shows below the name in a smaller, muted text

Behavior

Sign-In Flow

  1. User clicks on the guest avatar
  2. Dropdown shows “Sign in to your account”
  3. Click “Sign in” button
  4. Triggers signIn() from useAuth hook
  5. Redirects to Logto authentication

Sign-Out Flow

  1. User clicks “Sign out” button
  2. Calls signOut({ callbackUrl, global }) from useAuth hook
  3. If globalSignOut={true}: Logs out from entire Logto ecosystem
  4. If globalSignOut={false}: Only clears local session
  5. Redirects to signoutCallbackUrl or current page

Customization

Custom Icons

You can use any icon library with additionalPages:

Dark Mode Support

The default theme classes support dark mode:
Customize for your design system:

SSR Considerations

The component includes built-in SSR handling to prevent hydration mismatches. It waits for client-side mounting before rendering user-specific content.

Dependencies

The component requires these shadcn/ui components:
  • Avatar, AvatarFallback, AvatarImage
  • DropdownMenu family
  • Button
Icons from lucide-react:
  • User
  • LogOut
  • UserCircle

Best Practices

Ensure UserCenter is used within an AuthProvider to access authentication context.
Set signoutCallbackUrl to control where users land after signing out.
Keep globalSignOut={true} (default) for better security, clearing all sessions across devices.
Use additionalPages to provide quick access to user-related pages like settings, profile, and billing.

Troubleshooting

If the component doesn’t show user information after sign-in, ensure the AuthProvider is properly configured and wrapping your app.
For popup sign-in, make sure your /signin page properly handles the ?popup=true query parameter.

AuthProvider

Main authentication provider

useAuth Hook

Access authentication in any component

CallbackPage

Handle authentication callbacks

Route Protection

Protect routes from unauthorized access