Overview
The API Client module provides a configured Axios instance for making HTTP requests to the RIS Gran Chimú backend, along with utilities for managing authentication tokens.Configuration
BASE_URL
apiClient
- baseURL: Points to the RIS Gran Chimú backend API
- timeout: 10 second request timeout
- headers: Default Content-Type set to application/json
Functions
setAuthToken
Sets or removes the Authorization header for all API requests.Authentication token to set. Pass
null to remove the Authorization header.Behavior
- If
tokenis provided, sets theAuthorizationheader toBearer {token} - If
tokenisnull, removes theAuthorizationheader from all requests - Logs the action to console for debugging
Implementation Details
Location:src/services/apiClient.ts:21
The function modifies apiClient.defaults.headers.common['Authorization'] to ensure all subsequent requests include the authentication token.
getStoredToken
Retrieves the stored authentication token from secure storage and applies it to the API client.Returns the stored authentication token if found, or
null if not found or an error occurred.Behavior
- Retrieves the token from Expo SecureStore using key
'authToken' - If a token is found, automatically applies it using
setAuthToken() - Returns the token value or
nullif not found - Catches and logs any errors during retrieval
Implementation Details
Location:src/services/apiClient.ts:32
This function is typically called during app initialization to restore authentication state from previous sessions.
Usage Example
Dependencies
axios: HTTP client libraryexpo-secure-store: Secure storage for sensitive data like authentication tokens
