BigBlocks Docs
Components/Authentication

SignOutButton

Secure sign-out button with confirmation dialog and session cleanup

A secure sign-out button component that handles session cleanup while preserving encrypted backups. It features optional confirmation dialogs, loading states, and customizable appearance to fit various UI contexts.

Installation

npx bigblocks add sign-out-button

Import

import { SignOutButton } from 'bigblocks';

Props

PropTypeRequiredDefaultDescription
redirectTostringNo'/'URL to redirect after sign out
confirmSignOutbooleanNofalseShow confirmation dialog
confirmMessagestringNo'Are you sure you want to sign out?'Custom confirmation message
variant'solid' | 'soft' | 'outline' | 'ghost'No'soft'Button style variant
color'gray' | 'red' | 'orange' | 'blue' | 'green'No'gray'Button color
size'1' | '2' | '3' | '4'No'3'Button size (Radix scale)
showIconbooleanNotrueShow exit icon
childrenReact.ReactNodeNo'Sign Out'Custom button text
classNamestringNo-Additional CSS classes
onSignOut() => voidNo-Callback after sign out
showClearInfobooleanNofalseShow what will be cleared

Basic Usage

import { SignOutButton } from 'bigblocks';

export default function Header() {
  return (
    <nav className="flex justify-between items-center p-4">
      <h1>My App</h1>
      <SignOutButton />
    </nav>
  );
}

Advanced Usage

With Confirmation Dialog

import { SignOutButton } from 'bigblocks';

export default function SecuritySettings() {
  return (
    <SignOutButton 
      confirmSignOut={true}
      confirmMessage="Are you sure you want to sign out? You'll need your password to sign back in."
      color="red"
      variant="solid"
    />
  );
}

Custom Sign Out Handler

import { SignOutButton } from 'bigblocks';

export default function ProfileMenu() {
  const handleSignOut = async () => {
    // Clean up app-specific data
    await clearLocalCache();
    
    // Track analytics
    analytics.track('user_signed_out', {
      location: 'profile_menu',
      timestamp: Date.now()
    });
    
    // Show toast notification
    toast.success('Signed out successfully');
  };

  return (
    <SignOutButton
      onSignOut={handleSignOut}
      redirectTo="/goodbye"
      variant="ghost"
    />
  );
}

With Clear Info Display

import { SignOutButton } from 'bigblocks';

export default function DetailedSignOut() {
  return (
    <SignOutButton
      confirmSignOut={true}
      showClearInfo={true}
      confirmMessage="Ready to sign out?"
      color="orange"
      size="3"
    />
  );
}

In Dropdown Menu

import { SignOutButton } from 'bigblocks';
import { DropdownMenu } from '@radix-ui/themes';

export function UserMenu() {
  return (
    <DropdownMenu.Root>
      <DropdownMenu.Trigger>
        <button>User Menu</button>
      </DropdownMenu.Trigger>
      
      <DropdownMenu.Content>
        <DropdownMenu.Item>Profile</DropdownMenu.Item>
        <DropdownMenu.Item>Settings</DropdownMenu.Item>
        <DropdownMenu.Separator />
        
        <DropdownMenu.Item asChild>
          <SignOutButton 
            variant="ghost"
            className="w-full justify-start"
            size="2"
          />
        </DropdownMenu.Item>
      </DropdownMenu.Content>
    </DropdownMenu.Root>
  );
}

Common Patterns

Header Integration

import { SignOutButton } from 'bigblocks';
import { useAuth } from '@/hooks/useAuth';

export function AppHeader() {
  const { isAuthenticated } = useAuth();

  return (
    <header className="border-b">
      <div className="container mx-auto px-4 py-3 flex justify-between items-center">
        <h1 className="text-xl font-bold">My App</h1>
        
        {isAuthenticated && (
          <SignOutButton 
            variant="outline"
            size="2"
          />
        )}
      </div>
    </header>
  );
}

Mobile Responsive

import { SignOutButton } from 'bigblocks';

export function ResponsiveSignOut() {
  return (
    <SignOutButton
      size="2"
      variant="soft"
      className="md:hidden"
    >
      <span className="sr-only">Sign Out</span>
      <ExitIcon />
    </SignOutButton>
  );
}

Settings Page

import { SignOutButton } from 'bigblocks';

export function AccountSettings() {
  return (
    <div className="space-y-6">
      <section>
        <h2 className="text-lg font-semibold mb-4">Account</h2>
        
        <div className="border rounded-lg p-4">
          <h3 className="font-medium mb-2">Sign Out</h3>
          <p className="text-sm text-gray-600 mb-4">
            Sign out of your account. Your encrypted backup will be preserved.
          </p>
          
          <SignOutButton
            confirmSignOut={true}
            showClearInfo={true}
            color="red"
            variant="solid"
          />
        </div>
      </section>
    </div>
  );
}

Data Management

What Gets Cleared

When signing out, the following data is cleared:

  1. Session Storage

    • Decrypted backup data
    • Temporary authentication tokens
    • Active session information
  2. Authentication State

    • User context
    • Authentication status
    • Active profile
  3. Server Session

    • NextAuth session cookies
    • Server-side session data
  4. Cache

    • React Query cache
    • API response cache

What Gets Preserved

The following data remains after sign out:

  1. Encrypted Backup

    • Stored in localStorage
    • Password-protected
    • Ready for next sign in
  2. OAuth Links

    • Connected provider information
    • OAuth backup references
  3. User Preferences

    • Theme settings
    • UI preferences
    • Language settings

Confirmation Dialog

When confirmSignOut is enabled, the component shows a modal with:

  • Custom confirmation message
  • Clear information (if enabled)
  • Cancel button
  • Confirm button

Example dialog content:

Are you sure you want to sign out?

This will clear:
• Current session
• Temporary data

Your encrypted backup will remain safe.

[Cancel] [Sign Out]

Styling

The button uses Radix Themes styling system:

// Different variants
<SignOutButton variant="solid" />   // Filled background
<SignOutButton variant="soft" />    // Subtle background
<SignOutButton variant="outline" /> // Border only
<SignOutButton variant="ghost" />   // Minimal styling

// Different colors
<SignOutButton color="gray" />   // Default
<SignOutButton color="red" />    // Danger/warning
<SignOutButton color="orange" /> // Caution
<SignOutButton color="blue" />   // Info
<SignOutButton color="green" />  // Success

// Different sizes
<SignOutButton size="1" /> // Extra small
<SignOutButton size="2" /> // Small
<SignOutButton size="3" /> // Medium (default)
<SignOutButton size="4" /> // Large

Best Practices

  1. Confirmation for Important Flows: Enable confirmation when signing out would interrupt important work
  2. Color Coding: Use red color for emphasis in security contexts
  3. Placement: Common locations include headers, profile menus, and settings pages
  4. Clear Information: Show what will be cleared in sensitive applications
  5. Loading States: The button shows a spinner during the sign-out process

Accessibility

  • Auto-hide: Only renders when user is authenticated
  • Keyboard Navigation: Fully keyboard accessible
  • Screen Readers: Proper ARIA labels and announcements
  • Focus Management: Proper focus handling in confirmation dialog

Security Considerations

  1. Client-Side Cleanup: Ensures all sensitive session data is cleared
  2. Server Coordination: Properly invalidates server sessions
  3. Backup Protection: Never touches encrypted backup data
  4. No Data Loss: Preserves all persistent user data

Troubleshooting

Button Not Showing

  • Verify user is authenticated
  • Check that component is inside BitcoinAuthProvider
  • Ensure proper React Query setup

Sign Out Not Working

  • Check console for errors
  • Verify API endpoints are accessible
  • Ensure proper session configuration

Redirect Not Working

  • For Next.js apps, ensure router is properly configured
  • Check that redirect URL is valid
  • Verify no middleware is blocking navigation

API Reference

Internal Behavior

The component internally:

  1. Checks authentication status
  2. Clears session storage
  3. Calls sign out API
  4. Clears authentication context
  5. Redirects (if specified)
  6. Calls onSignOut callback

Session Cleanup

The sign-out process:

1. Clear sessionStorage
2. Clear authentication state
3. Invalidate server session
4. Clear React Query cache
5. Preserve encrypted backup
6. Redirect to specified URL