From 56711e9136b6ea1f2a189aa9a3c1cbbf90d14ea6 Mon Sep 17 00:00:00 2001 From: Koncept Kit <63216427+konceptkit@users.noreply.github.com> Date: Mon, 5 Jan 2026 15:47:30 +0700 Subject: [PATCH] Revert URL cleanup - backend path is correct The /membership path in backend URL is correct for development. Issue is CORS configuration on backend, not URL format. --- src/context/AuthContext.js | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/src/context/AuthContext.js b/src/context/AuthContext.js index b2aa1b7..24df9bf 100644 --- a/src/context/AuthContext.js +++ b/src/context/AuthContext.js @@ -3,34 +3,14 @@ import axios from 'axios'; const AuthContext = createContext(); -// Ensure API_URL is correctly set, with fallback and validation -const getApiUrl = () => { - const url = process.env.REACT_APP_BACKEND_URL; +const API_URL = process.env.REACT_APP_BACKEND_URL || window.location.origin; - // Log the environment variable for debugging - console.log('[AuthContext] Environment check:', { - REACT_APP_BACKEND_URL: url, - REACT_APP_BASENAME: process.env.REACT_APP_BASENAME, - PUBLIC_URL: process.env.PUBLIC_URL - }); - - if (!url) { - console.error('[AuthContext] REACT_APP_BACKEND_URL is not defined!'); - // Fallback to current origin API (same domain) - return window.location.origin.replace('/membership', ''); - } - - // Remove any trailing /membership or /api from the backend URL - const cleanUrl = url.replace(/\/(membership|api)\/?$/, ''); - - if (cleanUrl !== url) { - console.warn('[AuthContext] Cleaned backend URL:', { original: url, cleaned: cleanUrl }); - } - - return cleanUrl; -}; - -const API_URL = getApiUrl(); +// Log environment on module load for debugging +console.log('[AuthContext] Module initialized with:', { + REACT_APP_BACKEND_URL: process.env.REACT_APP_BACKEND_URL, + REACT_APP_BASENAME: process.env.REACT_APP_BASENAME, + API_URL: API_URL +}); export const AuthProvider = ({ children }) => { const [user, setUser] = useState(null);