API Reference
Core Functions
getReclaimAuth
Initializes and returns a ReclaimAuth instance for handling authentication flows.
Parameters:
clientId
: Your application's unique identifierclientSecret
: Your application's secret keyredirectUri
: The URI where users will be redirected after authentication
Returns: A ReclaimAuth instance with authentication methods
ReclaimAuth Methods
signIn()
: Initiates the authentication flow and returns the user datasignOut()
: Logs out the current user and clears authentication stategetCurrentUser()
: Returns the currently authenticated user or nullonAuthStateChanged()
: Subscribes to authentication state changes and returns an unsubscribe function
Types
ReclaimUser
Represents an authenticated user's data structure:
id
: Unique identifier for the useruserData
: Primary user information key-value pairsadditionalData
: Array of supplementary user information
AuthError
Extended error type for authentication-specific errors, including error codes and additional details.
React Hooks
useReclaimAuth
Primary hook for managing authentication state and actions in React components. Provides complete authentication functionality.
useAuthState
Simplified hook for accessing authentication state only. Useful when you only need to check user status.
useAuthActions
Hook for accessing authentication actions without state management.
React Components
AuthProvider
Context provider component that must wrap any part of the application using authentication features.
ProtectedRoute
Component for protecting routes that require authentication. Redirects unauthenticated users to the login page.
Error Codes
Code | Description |
---|---|
popup_blocked | Authentication popup was blocked |
unauthorized | Client is not authorized |
invalid_request | Invalid request parameters |
network_error | Network connectivity issues |
auth_cancelled | User 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