Overview
TheUserCenter 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
Additional CSS classes to apply to the avatar element. ```tsx
URL to redirect to after sign-out. Defaults to current page. ```tsx
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.avatarexists, 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
- User clicks on the guest avatar
- Dropdown shows “Sign in to your account”
- Click “Sign in” button
- Triggers
signIn()fromuseAuthhook - Redirects to Logto authentication
Sign-Out Flow
- User clicks “Sign out” button
- Calls
signOut({ callbackUrl, global })fromuseAuthhook - If
globalSignOut={true}: Logs out from entire Logto ecosystem - If
globalSignOut={false}: Only clears local session - Redirects to
signoutCallbackUrlor current page
Customization
Custom Icons
You can use any icon library withadditionalPages:
Dark Mode Support
The default theme classes support dark mode: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,AvatarImageDropdownMenufamilyButton
lucide-react:
UserLogOutUserCircle
Best Practices
Always wrap with AuthProvider
Always wrap with AuthProvider
Ensure
UserCenter is used within an AuthProvider to access authentication context.Configure sign-out redirect
Configure sign-out redirect
Set
signoutCallbackUrl to control where users land after signing out.Use global sign-out for security
Use global sign-out for security
Keep
globalSignOut={true} (default) for better security, clearing all sessions across devices.Add relevant pages
Add relevant pages
Use
additionalPages to provide quick access to user-related pages like settings, profile, and billing.Troubleshooting
Related
AuthProvider
Main authentication provider
useAuth Hook
Access authentication in any component
CallbackPage
Handle authentication callbacks
Route Protection
Protect routes from unauthorized access