Fix frontend auth API base URL (Vercel)#30
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0cbf5c7021
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| env?: Record<string, string | undefined>; | ||
| }).env; | ||
|
|
||
| const configuredApiUrl = frontendEnv?.VITE_API_URL?.trim(); |
There was a problem hiding this comment.
Preserve backward compatibility for API env variable
Reading only VITE_API_URL introduces a silent regression for existing deployments that still define VITE_API_BASE_URL (the previously documented key): after upgrading, configuredApiUrl becomes empty and the code falls back to window.location.origin, so auth/API calls are sent to the frontend origin and fail whenever frontend and backend are on different hosts. Please support both names during migration (e.g., prefer VITE_API_URL but fall back to VITE_API_BASE_URL) to avoid breaking current environments.
Useful? React with 👍 / 👎.
Motivation
VITE_API_URL) while still falling back to same-origin for local single-server mode.Description
frontend/src/api.tsto readimport.meta.env.VITE_API_URLand usewindow.location.originas a fallback.console.errorwhenVITE_API_URLis not configured that instructs operators to setVITE_API_URL(example:https://gitplant-backend.vercel.app)./auth/login) use the sharedbuildApiUrlhelper so they target the configured base URL.frontend/README.mdand addedfrontend/.env.examplewithVITE_API_URLfor local/dev setup.Testing
npm --prefix frontend run buildand the build completed successfully.VITE_API_URL=http://127.0.0.1:8000and executed automated Playwright checks that clicked the Sign in button and observed aPOST /auth/loginrequest, confirming requests are routed via the configured base URL.VITE_API_URL=https://gitplant-backend.vercel.appin the Vercel frontend project or infrontend/.env, runnpm --prefix frontend run dev, open the app and click Sign in and verify aPOSTis sent to${VITE_API_URL}/auth/loginand successful login navigates to the dashboard; removeVITE_API_URLand refresh to confirm a clearconsole.erroris emitted and the app falls back to same-origin.Codex Task