✨Works out of the box guarantee. If you face any issue at all, hit us up on Telegram and we will write the integration for you.

OAuth ReactJS
Handling Errors

Error Handling

Common Errors

Popup Blocked

try {
  await auth.signIn();
} catch (error) {
  if (error.code === 'popup_blocked') {
    // Handle popup blocked
  }
}

Network Errors

try {
  await auth.signIn();
} catch (error) {
  if (error.code === 'network_error') {
    // Handle network issues
  }
}

Authentication Cancelled

try {
  await auth.signIn();
} catch (error) {
  if (error.code === 'auth_cancelled') {
    // Handle user cancellation
  }
}

Error Boundaries

class AuthErrorBoundary extends React.Component {
  state = { hasError: false, error: null };
 
  static getDerivedStateFromError(error) {
    return { hasError: true, error };
  }
 
  render() {
    if (this.state.hasError) {
      return <ErrorDisplay error={this.state.error} />;
    }
 
    return this.props.children;
  }
}

Best Practices

  1. Always implement error handling
  2. Use appropriate error boundaries
  3. Provide user feedback
  4. Log errors appropriately
  5. Implement retry mechanisms

Example Implementation

function LoginComponent() {
  const [error, setError] = useState<Error | null>(null);
  const [retries, setRetries] = useState(0);
  const { signIn } = useReclaimAuth();
 
  const handleLogin = async () => {
    try {
      setError(null);
      await signIn();
    } catch (err) {
      setError(err);
      
      // Handle specific errors
      if (err.code === 'popup_blocked') {
        alert('Please enable popups for this site');
      } else if (err.code === 'network_error' && retries < 3) {
        setRetries(r => r + 1);
        // Implement exponential backoff
        setTimeout(handleLogin, Math.pow(2, retries) * 1000);
      } else if (err.code === 'auth_cancelled') {
        // User cancelled, no need for error display
        setError(null);
      }
    }
  };
 
  if (error) {
    return (
      <div className="error-container">
        <p>Error: {error.message}</p>
        <button onClick={handleLogin}>Try Again</button>
      </div>
    );
  }
 
  return <button onClick={handleLogin}>Sign In</button>;
}