Why this matters now: useAuth.ts handles the entire authentication flow: challenge generation, wallet-based signing (Freighter/Lobstr/keypair), JWT issuance, profile setup, and re-authentication. This is the most security-critical hook in the app — a bug here could lock users out, issue invalid tokens, or expose signing keys. It has zero test coverage.
Problem / What: src/hooks/useAuth.ts (130 lines) — no corresponding test file in src/__tests__/. The hook has complex branching: three signing paths (Lobstr line 41, Freighter line 49, keypair line 52), error handling (lines 79-81), profile sync (lines 89-107), and integration with two Zustand stores.
Key Challenges:
- Mock
getAuthChallenge, loginWithWallet, fetchUserProfile from api.ts.
- Mock
signChallengeXDR from stellar.ts.
- Mock
openLobstrForSigning from lobstr.ts.
- Mock
getInAppSecret from walletVault.ts.
- Mock
useWalletStore and useUserStore Zustand stores.
- Test all three signing paths (Lobstr, Freighter, keypair).
- Test error handling: network failure, invalid challenge, missing secret key.
- Test
syncProfile with server success and failure.
Acceptance Criteria:
- Test file
src/__tests__/useAuth.test.ts with 15+ test cases.
- All three signing paths covered (Lobstr, Freighter, keypair).
- Error scenarios: network failure, missing key, auth challenge failure.
- Profile sync: success, failure, partial data.
syncProfile doesn't overwrite existing stats.
- All tests pass with
npm test.
Relevant files/functions:
src/hooks/useAuth.ts (entire file)
src/__tests__/useAuth.test.ts (new)
Out of scope: End-to-end auth flow with real backend.
Labels: testing, advanced, security, wallet
Why this matters now:
useAuth.tshandles the entire authentication flow: challenge generation, wallet-based signing (Freighter/Lobstr/keypair), JWT issuance, profile setup, and re-authentication. This is the most security-critical hook in the app — a bug here could lock users out, issue invalid tokens, or expose signing keys. It has zero test coverage.Problem / What:
src/hooks/useAuth.ts(130 lines) — no corresponding test file insrc/__tests__/. The hook has complex branching: three signing paths (Lobstr line 41, Freighter line 49, keypair line 52), error handling (lines 79-81), profile sync (lines 89-107), and integration with two Zustand stores.Key Challenges:
getAuthChallenge,loginWithWallet,fetchUserProfilefromapi.ts.signChallengeXDRfromstellar.ts.openLobstrForSigningfromlobstr.ts.getInAppSecretfromwalletVault.ts.useWalletStoreanduseUserStoreZustand stores.syncProfilewith server success and failure.Acceptance Criteria:
src/__tests__/useAuth.test.tswith 15+ test cases.syncProfiledoesn't overwrite existing stats.npm test.Relevant files/functions:
src/hooks/useAuth.ts(entire file)src/__tests__/useAuth.test.ts(new)Out of scope: End-to-end auth flow with real backend.
Labels:
testing,advanced,security,wallet