Skip to content

fix: align frontend API client with actual backend API - #89

Merged
Nabeelahh merged 1 commit into
Vaulty-X:mainfrom
Myart352:fix/align-api-client-with-backend
Jul 29, 2026
Merged

fix: align frontend API client with actual backend API#89
Nabeelahh merged 1 commit into
Vaulty-X:mainfrom
Myart352:fix/align-api-client-with-backend

Conversation

@Myart352

Copy link
Copy Markdown

Closes #14

Summary

Aligns the frontend API client with the actual backend API that runs on port 3000 with the /api/v1 prefix.

Changes

API Base URL

  • Changed from http://localhost:8000/api to http://localhost:3000/api/v1
  • Added NEXT_PUBLIC_API_URL env var (replaces old NEXT_PUBLIC_BACKEND_API_URL)
  • Updated .env.example

Types (Frontend/src/types/index.ts)

  • Added ApiResponse<T> and PaginatedResponse<T> response wrapper types
  • Added auth types: User, RegisterInput, LoginInput, LoginResponse, etc.
  • Updated vault types to match backend schema (currentAmount as string, status, type)
  • Added VaultTransaction, VaultTransactionType, VaultTransactionStatus
  • Added ApiValidationError for structured error handling
  • Deprecated old Deposit/Withdrawal interfaces

API Client (Frontend/src/lib/api.ts)

  • Added token management with setAccessToken/getAccessToken
  • Added Authorization: Bearer header injection on all requests
  • Added X-Idempotency-Key header support for idempotent operations
  • Added auth methods: register, login, refreshToken, logout, logoutAll, forgotPassword, resetPassword, verifyEmail, getProfile, updateProfile
  • Added vault methods: getVaults, getVault, createVault, depositToVault, withdrawFromVault, lockVault, unlockVault, closeVault, getVaultHistory
  • Added transaction methods: submitTransaction, getTransactionStatus
  • Improved ApiError class with backend error code parsing
  • Legacy fiat methods kept as stubs (throw 501 until fiat endpoints exist)
  • Added ApiResponse unwrapping for {success, data} envelope

State Management (Frontend/src/stores/index.ts)

  • Added auth state: accessToken, refreshToken, user
  • Added setTokens, setUser, clearAuth actions
  • Tokens synced to API client via setAccessToken/setRefreshToken

Hooks

  • useAuth.ts (new): auth hook with login, register, logout, profile, token refresh with automatic retry on 401
  • useVault.ts: connected to real API endpoints, added fetchVaults, fetchVault, initiateFunding, initiateWithdrawal, lockVault, unlockVault, closeVault

Testing

  • All modified files pass TypeScript typechecking (0 errors)
  • Pre-existing type errors in CreateVault.tsx (corrupted file) are unrelated

- Fix API base URL from port 8000 to 3000 with /api/v1 prefix
- Add typed auth methods (register, login, refresh, logout, profile)
- Add typed vault methods (CRUD, deposit, withdraw, lock, unlock, close)
- Add typed transaction methods (submit, getStatus)
- Add auth state management to Zustand store with token sync
- Add useAuth hook with auto-refresh on 401
- Connect useVault hook to real API endpoints
- Update .env.example with new NEXT_PUBLIC_API_URL var
- Add API response wrapper types (ApiResponse, PaginatedResponse)
- Add proper error parsing with backend error codes
@Nabeelahh
Nabeelahh merged commit 8d7ccec into Vaulty-X:main Jul 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Frontend] Align the API client with the actual backend API

2 participants