Skip to content

Conversation

andypols
Copy link
Contributor

@andypols andypols commented Sep 12, 2025

Summary

This PR fixes a production logout failure caused by the client defaulting to http://localhost:3000 when VITE_API_URI is unset.

Root Cause

In src/ui/components/Navbars/DashboardNavbarLinks.tsx we have:

      const { data } = await axios.post(
        `${process.env.VITE_API_URI || 'http://localhost:3000'}/api/auth/logout`,
        {},
        getAxiosConfig(),
      );

Because VITE_API_URI isn’t set in prod, the code hit the localhost fallback.

Different areas of the code use different patterns, leading to inconsistent behaviour:

  • src/ui/views/Login/Login.tsx:
const loginUrl = `${process.env.VITE_API_URI}/api/auth/login`;
  • src/ui/services/user.ts:
const baseUrl = process.env.VITE_API_URI || location.origin;

Note: in Vite client code we should prefer import.meta.env.VITE_API_URI over process.env.* but that does not work until we upgrade typescript config to use ES Modules (and not "CommonJS").

Fix

What this PR changes

  • Introduces a single source of truth for the API base.
  • Switches all API calls to use relative URLs by default, with an optional env override.
  • Removes hardcoded localhost and location.origin fallbacks from call sites.

Copy link

netlify bot commented Sep 12, 2025

Deploy Preview for endearing-brigadeiros-63f9d0 canceled.

Name Link
🔨 Latest commit 519b53d
🔍 Latest deploy log https://app.netlify.com/projects/endearing-brigadeiros-63f9d0/deploys/68cd543425a15b00086b6e78

@github-actions github-actions bot added the fix label Sep 12, 2025
Copy link

codecov bot commented Sep 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.87%. Comparing base (a15adf1) to head (519b53d).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1201      +/-   ##
==========================================
+ Coverage   83.86%   83.87%   +0.01%     
==========================================
  Files          67       68       +1     
  Lines        2906     2908       +2     
  Branches      366      367       +1     
==========================================
+ Hits         2437     2439       +2     
  Misses        409      409              
  Partials       60       60              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@andypols andypols requested a review from JamieSlome September 16, 2025 07:31
@andypols
Copy link
Contributor Author

Please can a @finos/git-proxy-maintainers review this for me - thanks

Copy link
Contributor

@kriswest kriswest left a comment

Choose a reason for hiding this comment

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

@andy_pols, sorry for the delay, I'm travelling. I hope to test this against an LDAP server, but that sometimes take a while to arrange.

There are a few additional VITE_API_URI references that could be replaced with API_BASE:

  • /src/ui/services/auth.js
  • /src/ui/services/config.js
  • /src/ui/services/git-push.js
  • /src/ui/services/repo.js

i.e. the UI services that haven't been converted to TS.

Otherwise this looks good to me! Thanks for taking it on.

Copy link
Contributor

@jescalada jescalada left a comment

Choose a reason for hiding this comment

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

LGTM! Just wondering if we can use the API_BASE instead of envs in git-proxy-cli/index.js:

const { GIT_PROXY_UI_HOST: uiHost = 'http://localhost', GIT_PROXY_UI_PORT: uiPort = 8080 } =
  process.env;

const baseUrl = `${uiHost}:${uiPort}`;

@andypols
Copy link
Contributor Author

LGTM! Just wondering if we can use the API_BASE instead of envs in git-proxy-cli/index.js:

const { GIT_PROXY_UI_HOST: uiHost = 'http://localhost', GIT_PROXY_UI_PORT: uiPort = 8080 } =
  process.env;

const baseUrl = `${uiHost}:${uiPort}`;

No because the proxy and the API are separate and may not have the same DNS (we have different DNS's domain names for the proxy and the app).

Copy link
Contributor

@kriswest kriswest left a comment

Choose a reason for hiding this comment

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

As we can't (shouldn't?) use API_BASE in the JS UI services until converted to TS, I think this is good to go.

@kriswest kriswest merged commit 169e0f3 into finos:main Sep 19, 2025
14 checks passed
@andypols andypols deleted the fix-logout-baseurl branch September 22, 2025 08:12
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.

4 participants