chore: migrate API client to new /v1 route prefix#25
Merged
Conversation
api-template moved every application route under /v1 (ag-tech-group/api-template#21). Infrastructure routes (/, /health, /docs, /openapi.json) stay unversioned. The refresh cookie is now path-scoped to /v1/auth/refresh, so silent-refresh requests must hit that exact path for the cookie to be sent. Updated hand-written API paths: - src/api/api.ts: silent-refresh fetches /v1/auth/refresh; afterResponse loop guard recognizes /v1/auth/refresh and /v1/auth/jwt/logout - src/lib/auth.tsx: checkAuth -> /v1/auth/me; logout -> /v1/auth/jwt/logout - src/lib/feature-flags.tsx: FeatureFlagProvider -> /v1/flags - src/api/handlers.ts: MSW default handler -> /v1/auth/me - README: corresponding path references and cookie-path note baseUrl stays the bare origin (VITE_API_URL); /v1 lives in the request paths so orval-generated hooks and hand-written ky calls share the same contract and there's no /v1/v1/... duplication when pnpm generate-api is re-run against the updated spec. No vite proxy entries to rewrite — this template uses CORS via VITE_API_URL, not a dev proxy. Closes #24
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #24
api-template moved every application route under a
/v1prefix in ag-tech-group/api-template#21. Infrastructure routes (/,/health,/docs,/openapi.json) stay unversioned. The refresh cookie is now path-scoped to/v1/auth/refresh. This catches the web client up before it's pointed at an API built from the updated template.Path map applied
/auth/register,/auth/jwt/login,/auth/jwt/logout,/auth/refresh,/auth/me/v1/auth/.../admin/users/{id}/role/v1/admin/users/{id}/role/notes,/notes/{id}/v1/notes,/v1/notes/{id}/flags/v1/flags/,/health,/docs,/openapi.jsonWhat changed
5 files, +16/-12 — all hand-written API path strings:
src/api/api.ts— silent-refreshfetch()targets/v1/auth/refresh; theafterResponse"don't refresh on the refresh request" guard now matches/v1/auth/refreshand/v1/auth/jwt/logout.src/lib/auth.tsx—checkAuth()calls/v1/auth/me;logout()calls/v1/auth/jwt/logout.src/lib/feature-flags.tsx—FeatureFlagProviderfetches/v1/flags.src/api/handlers.ts— MSW default unauthenticated handler now matches*/v1/auth/me.README.md—/auth/me,/auth/refresh,/flagsreferences updated; documented that the refresh cookie is path-scoped to/v1/auth/refresh.Codegen path note (from issue checklist):
baseUrlstays the bare origin (VITE_API_URL, e.g.http://localhost:8000). The/v1lives in the request paths — both in hand-written ky calls (api.get("v1/auth/me")) and in the orval-generated hooks (which produce strings like`/v1/auth/me`). Runningpnpm generate-apiagainst a/v1-prefixed spec drops them straight into the generated client; nothing inbaseUrlto fight over, no/v1/v1/...duplication.Dev proxy note:
vite.config.tshas noserver.proxy— this template uses CORS viaVITE_API_URL, not a/api-style proxy. Nothing to rewrite there.The generated orval client (
src/api/generated/) is not committed — the template has never committed it, and theverify-api-typesCI job is gated onvars.OPENAPI_URL. Consumers regenerate against their own backend.Verification
Backend smoke test against a fresh
api-templatecheckout ofmain(uv sync,alembic upgrade head,uv run uvicorn app.main:app):GET /auth/me,POST /auth/jwt/login,POST /auth/refresh,GET /flags,GET /notes./,/health,/docs,/openapi.json.POST /v1/auth/register→ 201 →POST /v1/auth/jwt/login→ 204 withapp_access(Path=/) andapp_refresh(Path=/v1/auth/refresh).GET /v1/auth/mewith cookies → 200;GET /v1/notes→ 200.POST /v1/auth/refresh→ 204 (cookies rotated, refresh cookie stillPath=/v1/auth/refresh); subsequentGET /v1/auth/mewith rotated cookies → 200.POST /v1/auth/jwt/logout→ 204; subsequentGET /v1/auth/me→ 401.GET /v1/auth/mecarries onlyapp_access;POST /v1/auth/refreshcarries both. Confirms the frontend must request the exact path/v1/auth/refreshfor the refresh cookie to be sent — which is whatattemptRefresh()now does.Codegen check:
OPENAPI_URL=http://localhost:<port>/openapi.json pnpm generate-apiproduces hooks likeuseGetV1AuthMecalling`/v1/auth/me`, no/v1/v1/...duplication.Local CI checks all green:
pnpm lint(0 errors; the 4 fast-refresh warnings insrc/routes/__root.tsxare pre-existing and the file isn't touched by this PR),pnpm format:check,pnpm tsc --noEmit,pnpm test:run(2/2). Husky pre-commit ran the productionvite buildcleanly.Recommend a manual browser pass locally before merge: with
VITE_API_URL=http://localhost:8000and a/v1-prefixed api-template running, openhttp://localhost:5173and confirm the initialGET /v1/auth/me(401) andGET /v1/flagsrequests fire in the network panel, with no/auth/meor/flagsrequests appearing.