✨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.
logoReclaim Protocol Docs

API Reference

Core Functions

getReclaimAuth

function getReclaimAuth(
  clientId: string,
  cliendSecret: string,
  redirectUri: string
): ReclaimAuth

Initializes and returns a ReclaimAuth instance for handling authentication flows.

Parameters:

  • clientId: Your application's unique identifier
  • clientSecret: Your application's secret key
  • redirectUri: The URI where users will be redirected after authentication

Returns: A ReclaimAuth instance with authentication methods

ReclaimAuth Methods

interface ReclaimAuth {
  signIn(): Promise<ReclaimUser>;
  signOut(): Promise<void>;
  getCurrentUser(): ReclaimUser | null;
  onAuthStateChanged(callback: (user: ReclaimUser | null) => void): () => void;
}
  • signIn(): Initiates the authentication flow and returns the user data
  • signOut(): Logs out the current user and clears authentication state
  • getCurrentUser(): Returns the currently authenticated user or null
  • onAuthStateChanged(): Subscribes to authentication state changes and returns an unsubscribe function

Types

ReclaimUser

interface ReclaimUser {
  id: string;
  userData: {
      [key: string]: string;
  }
  additionalData: {
      [key: string]: string;
  }[];
}

Represents an authenticated user's data structure:

  • id: Unique identifier for the user
  • userData: Primary user information key-value pairs
  • additionalData: Array of supplementary user information

AuthError

interface AuthError extends Error {
  code?: string;
  details?: unknown;
}

Extended error type for authentication-specific errors, including error codes and additional details.

React Hooks

useReclaimAuth

function useReclaimAuth(): {
  user: ReclaimUser | null;
  loading: boolean;
  error: Error | null;
  signIn: () => Promise<void>;
  signOut: () => Promise<void>;
  getCurrentUser: () => ReclaimUser | null;
}

Primary hook for managing authentication state and actions in React components. Provides complete authentication functionality.

useAuthState

function useAuthState(): {
  user: ReclaimUser | null;
  loading: boolean;
}

Simplified hook for accessing authentication state only. Useful when you only need to check user status.

useAuthActions

function useAuthActions(): {
  signIn: () => Promise<void>;
  signOut: () => Promise<void>;
}

Hook for accessing authentication actions without state management.

React Components

AuthProvider

function AuthProvider(props: { children: React.ReactNode }): JSX.Element

Context provider component that must wrap any part of the application using authentication features.

ProtectedRoute

function ProtectedRoute(props: { 
  children: React.ReactNode 
}): JSX.Element

Component for protecting routes that require authentication. Redirects unauthenticated users to the login page.

Error Codes

CodeDescription
popup_blockedAuthentication popup was blocked
unauthorizedClient is not authorized
invalid_requestInvalid request parameters
network_errorNetwork connectivity issues
auth_cancelledUser cancelled authentication

Error Handling Best Practices:

  • Always wrap authentication calls in try-catch blocks
  • Check for specific error codes to handle different scenarios
  • Provide appropriate user feedback based on error types
  • Implement retry logic for network-related errors

On this page