BigBlocks Docs
Components/Authentication

AuthFlowOrchestrator

Unified authentication flow manager for intelligent routing through sign in, sign up, or wallet restoration

A comprehensive authentication flow manager that intelligently routes users through sign in, sign up, OAuth restoration, device linking, or file import flows. This component provides a unified entry point for all authentication scenarios with automatic flow detection and seamless transitions.

Installation

npx bigblocks add auth-flow-orchestrator

Import

import { AuthFlowOrchestrator } from 'bigblocks';

Props

PropTypeRequiredDefaultDescription
flowTypeAuthFlowTypeNo'unified'Initial flow type
initialStepAuthStepNo'initial'Starting step in the flow
enableOAuthbooleanNotrueEnable OAuth provider options
enableDeviceLinkbooleanNotrueEnable device linking flow
enableFileImportbooleanNotrueEnable file import for backups
enableLocalBackupbooleanNotrueEnable local backup storage
enableProfileSyncbooleanNofalseEnable profile synchronization
maxDiscoveryAttemptsnumberNo3Max attempts for profile discovery
oauthProvidersOAuthProvider[]No-Custom OAuth provider configuration
onSuccess(user: {id: string, address: string}) => voidNo-Success callback
onError(error: string) => voidNo-Error callback
onFlowChange(flow: AuthFlowType) => voidNo-Flow change callback
onStepChange(step: AuthStep) => voidNo-Step change callback
titlestringNo-Custom title
subtitlestringNo-Custom subtitle
showHeaderbooleanNotrueShow header section
showFooterbooleanNotrueShow footer section
classNamestringNo-Additional CSS classes
layout'centered' | 'full' | 'custom'No'centered'Layout style
customLayoutReact.ComponentTypeNo-Custom layout component
autoDetectFlowbooleanNotrueAuto-detect best flow
persistFlowbooleanNotruePersist flow state
debugbooleanNofalseEnable debug mode

Flow Types

type AuthFlowType = 
  | 'unified'      // Auto-detect best flow
  | 'signin'       // Direct sign in
  | 'signup'       // New account creation
  | 'oauth-restore' // Restore via OAuth
  | 'device-link'  // Link new device
  | 'import'       // Import backup file
  | 'custom';      // Custom flow

Auth Steps

type AuthStep = 
  | 'initial'           // Starting point
  | 'signin'           // Sign in form
  | 'signup'           // Sign up form
  | 'password'         // Password entry
  | 'confirm-password' // Password confirmation
  | 'backup-display'   // Show backup
  | 'backup-download'  // Download backup
  | 'oauth-link'       // Link OAuth provider
  | 'oauth-restore'    // Restore from OAuth
  | 'import-backup'    // Import backup file
  | 'success';         // Success state

Basic Usage

import { AuthFlowOrchestrator, BitcoinAuthProvider } from 'bigblocks';
import { useRouter } from 'next/navigation';

export default function AuthPage() {
  const router = useRouter();

  return (
    <BitcoinAuthProvider config={{ apiUrl: '/api' }}>
      <AuthFlowOrchestrator
        onSuccess={(user) => {
          console.log('Auth successful:', user);
          router.push('/dashboard');
        }}
        onError={(error) => {
          console.error('Auth failed:', error);
        }}
      />
    </BitcoinAuthProvider>
  );
}

Advanced Usage

Specific Flow Type

import { AuthFlowOrchestrator } from 'bigblocks';

export default function SignUpOnly() {
  return (
    <AuthFlowOrchestrator
      flowType="signup"
      autoDetectFlow={false}
      onSuccess={(user) => {
        console.log('New user created:', user);
      }}
    />
  );
}

Custom OAuth Providers

import { AuthFlowOrchestrator } from 'bigblocks';
import { FaGoogle, FaGithub } from 'react-icons/fa';

export default function CustomOAuth() {
  const customProviders = [
    {
      id: 'google',
      name: 'Google',
      icon: <FaGoogle />
    },
    {
      id: 'github', 
      name: 'GitHub',
      icon: <FaGithub />
    }
  ];

  return (
    <AuthFlowOrchestrator
      oauthProviders={customProviders}
      enableOAuth={true}
      onSuccess={(user) => {
        console.log('OAuth auth successful');
      }}
    />
  );
}

Track Flow Progress

import { AuthFlowOrchestrator } from 'bigblocks';
import { useState } from 'react';

export default function TrackedAuth() {
  const [currentFlow, setCurrentFlow] = useState<AuthFlowType>('unified');
  const [currentStep, setCurrentStep] = useState<AuthStep>('initial');

  return (
    <div>
      <div className="mb-4">
        <p>Current Flow: {currentFlow}</p>
        <p>Current Step: {currentStep}</p>
      </div>
      
      <AuthFlowOrchestrator
        onFlowChange={setCurrentFlow}
        onStepChange={setCurrentStep}
        onSuccess={(user) => {
          analytics.track('auth_completed', {
            flow: currentFlow,
            userId: user.id
          });
        }}
      />
    </div>
  );
}

Custom Layout

import { AuthFlowOrchestrator } from 'bigblocks';

const CustomAuthLayout = ({ children }) => (
  <div className="custom-auth-container">
    <div className="auth-branding">
      <img src="/logo.png" alt="Logo" />
    </div>
    <div className="auth-content">
      {children}
    </div>
  </div>
);

export default function CustomLayoutAuth() {
  return (
    <AuthFlowOrchestrator
      layout="custom"
      customLayout={CustomAuthLayout}
      showHeader={false}
      onSuccess={(user) => {
        console.log('Auth completed');
      }}
    />
  );
}

Debug Mode

import { AuthFlowOrchestrator } from 'bigblocks';

export default function DebugAuth() {
  return (
    <AuthFlowOrchestrator
      debug={true}
      onSuccess={(user) => {
        console.log('Debug auth successful:', user);
      }}
      onError={(error) => {
        console.error('Debug auth error:', error);
      }}
    />
  );
}

Common Patterns

With Loading State

import { AuthFlowOrchestrator } from 'bigblocks';
import { useEffect, useState } from 'react';

export function SmartAuth() {
  const [hasExistingBackup, setHasExistingBackup] = useState(false);
  const [loading, setLoading] = useState(true);

  useEffect(() => {
    // Check for existing backup
    const backup = localStorage.getItem('encryptedBackup');
    setHasExistingBackup(!!backup);
    setLoading(false);
  }, []);

  if (loading) {
    return <div>Loading...</div>;
  }

  return (
    <AuthFlowOrchestrator
      flowType={hasExistingBackup ? 'signin' : 'signup'}
      autoDetectFlow={false}
      onSuccess={(user) => {
        console.log('Auth successful');
      }}
    />
  );
}

In Modal

import { AuthFlowOrchestrator } from 'bigblocks';
import { Modal } from '@radix-ui/themes';

export function AuthModal({ isOpen, onClose }) {
  return (
    <Modal open={isOpen} onOpenChange={onClose}>
      <Modal.Content maxWidth="450px">
        <AuthFlowOrchestrator
          layout="full"
          showHeader={false}
          onSuccess={(user) => {
            console.log('Modal auth successful');
            onClose();
          }}
        />
      </Modal.Content>
    </Modal>
  );
}

Profile Sync Enabled

import { AuthFlowOrchestrator } from 'bigblocks';

export function ProfileSyncAuth() {
  return (
    <AuthFlowOrchestrator
      enableProfileSync={true}
      maxDiscoveryAttempts={5}
      onSuccess={(user) => {
        console.log('Auth with profile sync completed');
      }}
    />
  );
}

Flow Behavior

Unified Flow (Default)

  • Detects if user has existing backup
  • Routes to appropriate flow automatically
  • Seamless transitions between states

Sign In Flow

  1. Password entry
  2. Backup decryption
  3. Identity verification
  4. Success

Sign Up Flow

  1. Identity generation
  2. Password creation
  3. Backup creation
  4. Download/save backup
  5. Optional OAuth linking
  6. Success

OAuth Restore Flow

  1. Select OAuth provider
  2. Authenticate with provider
  3. Retrieve encrypted backup
  4. Decrypt with password
  5. Success
  1. Generate device link code
  2. Scan QR or enter code
  3. Authorize on primary device
  4. Sync backup to new device
  5. Success

Troubleshooting

Flow Not Auto-Detecting

  • Check that autoDetectFlow is enabled
  • Verify local storage is accessible
  • Ensure BitcoinAuthProvider is properly configured

OAuth Not Working

  • Verify OAuth providers are configured in your backend
  • Check that enableOAuth is true
  • Ensure callback URLs are properly set

Custom Layout Issues

  • Layout component must accept children prop
  • Ensure proper CSS/styling is applied
  • Check that layout prop is set to 'custom'

API Reference

Success Callback

The onSuccess callback receives a user object:

{
  id: string;      // User's BAP ID
  address: string; // Bitcoin address
}

Error Handling

Errors are passed as strings to the onError callback. Common error types:

  • 'USER_EXISTS' - Account already exists
  • 'INVALID_PASSWORD' - Incorrect password
  • 'INVALID_BACKUP' - Corrupted backup file
  • 'OAUTH_FAILED' - OAuth authentication failed
  • 'DEVICE_LINK_FAILED' - Device linking failed

Flow State

The component manages internal state including:

  • Current flow type
  • Current step
  • Form data
  • Error states
  • Loading states

Notes for Improvement

Implementation Note: The prompt described props like mode, allowModeSwitch, showOAuthProviders, and customSteps which don't exist in the actual implementation. The actual component uses flowType, enableOAuth, and other boolean flags for configuration. The component is more feature-rich than the prompt suggested, with support for device linking, profile sync, and debug mode.