Mobile API requests authenticated via OAuth2 bearer tokens bypassed the
Terms gate that the root loader applies to web cookie sessions. Extend
requireApiUser to compare the user's termsVersion with TERMS_VERSION
and return a structured 403 { code: "TERMS_OUTDATED", currentTermsVersion }
on mismatch so mobile clients can surface their own re-acceptance UI.
Spec delta on journal-auth captures the new requirement.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
843 B
843 B
1. Implementation
- 1.1 Add
TERMS_OUTDATED: "TERMS_OUTDATED"toERROR_CODESinpackages/api/src/errors.ts. - 1.2 Extend
requireApiUserinapps/journal/app/lib/api-guard.server.tsto compare the authenticated user'stermsVersiontoTERMS_VERSION(from~/lib/legal). On mismatch (or NULL), throw aResponsewith status 403 and JSON body{ error, code: ERROR_CODES.TERMS_OUTDATED, currentTermsVersion: TERMS_VERSION }.
2. Tests
- 2.1 Add
apps/journal/app/lib/api-guard.server.test.tscovering: staletermsVersion→ 403 withTERMS_OUTDATED+currentTermsVersion; matchingtermsVersion→ returns user; nulltermsVersion→ 403; no auth → 401 (unchanged).
3. Verification
- 3.1 Run
pnpm typecheck && pnpm lint && pnpm test— all green. - 3.2 Open draft PR against
main.