Skip to content

feat: set up API client and HTTP layer with auth interceptors #48

Description

@Josue19-08

🔖 Title

Set up API client and HTTP layer with automatic JWT handling


📄 Description

All existing hooks (`use-sign-in`, `use-create-account`, `use-invest`) use `setTimeout` simulations or `console.log` instead of real API calls. There is no HTTP client configured in the project. This is the foundational piece that every other backend integration depends on.


✅ Tasks to complete

  • Install and configure `axios` (or `ky`) as the HTTP client
  • Create `src/lib/api-client.ts` with base URL from `EXPO_PUBLIC_API_URL` env variable
  • Add request interceptor to attach `Authorization: Bearer ` header
  • Add response interceptor to handle 401 errors: auto-refresh token via `POST /auth/refresh`, then retry original request
  • Create `src/lib/token-storage.ts` using `expo-secure-store` to persist `accessToken` and `refreshToken` securely
  • Create typed service modules: `auth.service.ts`, `loans.service.ts`, `merchants.service.ts`, `liquidity.service.ts`, `notifications.service.ts`
  • Add `EXPO_PUBLIC_API_URL` to `.env.example` and contributing guide
  • Add unit tests for the interceptor logic

📚 Documentation/context for AI

(This link never should removed)
https://github.com/TrustUp-app/TrustUp-API/tree/main/docs


🗒️ Additional notes

  • All API response shapes are documented in `TrustUp-API/docs/api/endpoints.md`
  • Use TypeScript interfaces to type all API responses — no `any`
  • The refresh token endpoint is `POST /auth/refresh` (body: `{ refreshToken }`)
  • On refresh failure (expired refresh token), clear storage and redirect user to sign in
  • Default base URL for local dev: `http://localhost:4000\`

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions