Setting up a reusable Axios instance keeps API configuration centralised. Rather than explicitly defining the base URL, timeouts, and headers for every individual call, the instance handles these details automatically. This removes redundant code.
Because interceptors execute just before a request leaves the app, they offer a highly reliable place to integrate authentication. In this setup, the interceptor fetches a stored token directly from expo-secure-store and attaches it as a Bearer token within the Authorization header. Approaching it this way extracts auth logic entirely from individual API calls. The token is applied by default whenever it is needed.
Axios handles network timeouts by rejecting the promise with an ECONNABORTED error. loginUser catches the error and returns { ok: false, error: "Request timed out" }. The UI then displays that message.