Skip to content

Fix frontend auth API base URL (Vercel)#30

Merged
gitgrahamdunn merged 1 commit intomainfrom
codex/fix-frontend-sign-in-api-integration
Feb 18, 2026
Merged

Fix frontend auth API base URL (Vercel)#30
gitgrahamdunn merged 1 commit intomainfrom
codex/fix-frontend-sign-in-api-integration

Conversation

@gitgrahamdunn
Copy link
Copy Markdown
Owner

Motivation

  • The frontend was hardcoded to call a localhost backend which breaks when the backend is deployed to Vercel.
  • Expose a Vite environment variable so the frontend can target the deployed backend (VITE_API_URL) while still falling back to same-origin for local single-server mode.

Description

  • Centralized API base URL resolution in frontend/src/api.ts to read import.meta.env.VITE_API_URL and use window.location.origin as a fallback.
  • Added a clear console.error when VITE_API_URL is not configured that instructs operators to set VITE_API_URL (example: https://gitplant-backend.vercel.app).
  • Left request paths unchanged and ensured all API calls (including /auth/login) use the shared buildApiUrl helper so they target the configured base URL.
  • Documented the env var in frontend/README.md and added frontend/.env.example with VITE_API_URL for local/dev setup.

Testing

  • Built the frontend with npm --prefix frontend run build and the build completed successfully.
  • Started the backend and dev frontend with VITE_API_URL=http://127.0.0.1:8000 and executed automated Playwright checks that clicked the Sign in button and observed a POST /auth/login request, confirming requests are routed via the configured base URL.
  • One automated run showed a CORS/preflight failure when calling an API origin that was not properly reachable in that environment, which validates that requests are now routed to the intended origin (and demonstrates why the deployed backend must allow the frontend origin).
  • How to test: set VITE_API_URL=https://gitplant-backend.vercel.app in the Vercel frontend project or in frontend/.env, run npm --prefix frontend run dev, open the app and click Sign in and verify a POST is sent to ${VITE_API_URL}/auth/login and successful login navigates to the dashboard; remove VITE_API_URL and refresh to confirm a clear console.error is emitted and the app falls back to same-origin.

Codex Task

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 18, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
gitplant Ready Ready Preview, Comment Feb 18, 2026 11:05pm
gitplant-backend Ready Ready Preview, Comment Feb 18, 2026 11:05pm
gitplant-oggy Ready Ready Preview, Comment Feb 18, 2026 11:05pm

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread frontend/src/api.ts
env?: Record<string, string | undefined>;
}).env;

const configuredApiUrl = frontendEnv?.VITE_API_URL?.trim();
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant