1daac47951
In Traefik deployment, API and web are on different domains. Frontend was using relative paths (/auth/login) which resolved to the web domain instead of the API domain. - Update LoginRedirectPage to use VITE_API_BASE_URL for login link - Update apiClient 401 interceptor to redirect to full API URL - Ensures OAuth flow works correctly with separate domains
27 lines
694 B
TypeScript
27 lines
694 B
TypeScript
import axios from "axios";
|
|
|
|
const BASE_URL = import.meta.env.VITE_API_BASE_URL ?? "http://localhost:8000";
|
|
|
|
export const apiClient = axios.create({
|
|
baseURL: BASE_URL,
|
|
withCredentials: true,
|
|
headers: {
|
|
"Content-Type": "application/json"
|
|
}
|
|
});
|
|
|
|
export const shouldSkipAuthRedirect = (path: string): boolean => {
|
|
return path.startsWith("/login") || path.startsWith("/auth");
|
|
};
|
|
|
|
apiClient.interceptors.response.use(
|
|
(response) => response,
|
|
(error) => {
|
|
const status = error?.response?.status;
|
|
if (status === 401 && !shouldSkipAuthRedirect(window.location.pathname)) {
|
|
window.location.assign(`${BASE_URL}/auth/login`);
|
|
}
|
|
return Promise.reject(error);
|
|
}
|
|
);
|