diff --git a/apps/client/.env b/apps/client/.env new file mode 100644 index 0000000..6412436 --- /dev/null +++ b/apps/client/.env @@ -0,0 +1 @@ +VITE_AUTH_SERVICE_URL=http://localhost:8080/auth-service \ No newline at end of file diff --git a/apps/client/.env.example b/apps/client/.env.example deleted file mode 100644 index 9955692..0000000 --- a/apps/client/.env.example +++ /dev/null @@ -1 +0,0 @@ -VITE_API_BASE_URL=http://192.168.0.1:3000 \ No newline at end of file diff --git a/apps/client/src/App.jsx b/apps/client/src/App.jsx index f69bf69..1c87732 100644 --- a/apps/client/src/App.jsx +++ b/apps/client/src/App.jsx @@ -15,12 +15,13 @@ function App() { const handleLogin = async () => { try { setIsLoading(true) - const url = `${import.meta.env.VITE_API_BASE_URL}/api/login` + const url = `${import.meta.env.VITE_AUTH_SERVICE_URL}/auth/login` + console.log('AUTH URL:', import.meta.env.VITE_AUTH_SERVICE_URL) const response = await fetchWithCred(url, { method: 'POST', body: JSON.stringify({ - username: 'alice', - password: 'secret123' + empLoginId: 'djhyoja', + empLoginPassword: '2145' }) }) if (!response.ok) { @@ -55,7 +56,7 @@ function App() { const handleLogout = async () => { try { setIsLoading(true) - const url = `${import.meta.env.VITE_API_BASE_URL}/api/logout` + const url = `${import.meta.env.VITE_AUTH_SERVICE_URL}/auth/logout` const response = await fetchWithCred(url, { method: 'POST', //...(csrfToken && { headers: { 'x-csrf-token': csrfToken }}) @@ -64,8 +65,7 @@ function App() { const data = await response.json() throw new ApiError(data.message || 'Failed to logout', response.status, data) } - const result = await response.json() - console.log('[Client] Logout response:', result) + console.log('[Client] Logout response:', response) setIsLogin(false) } catch(err) { if (err instanceof ApiError) { @@ -83,7 +83,7 @@ function App() { const handleProducts = async () => { try { setIsLoading(true) - const url = `${import.meta.env.VITE_API_BASE_URL}/api/products` + const url = `${import.meta.env.VITE_AUTH_SERVICE_URL}/api/products` const response = await fetchWithRefresh(url,{},{ retries: 5 }, csrfToken) if (!response.ok) { const data = await response.json() @@ -107,7 +107,7 @@ function App() { const handleRefresh = async () => { try { setIsLoading(true) - const url = `${import.meta.env.VITE_API_BASE_URL}/api/refresh` + const url = `${import.meta.env.VITE_AUTH_SERVICE_URL}/auth/refresh` const response = await fetchWithCred(url,{ method: 'POST', ...(csrfToken && { headers: { 'x-csrf-token': csrfToken }}) diff --git a/apps/client/src/lib/api.js b/apps/client/src/lib/api.js index 21beff4..6810805 100644 --- a/apps/client/src/lib/api.js +++ b/apps/client/src/lib/api.js @@ -48,7 +48,7 @@ export const fetchWithRefresh = async (url, options = {}, { retries = 1, timeout if (response.status === 401) { console.log('Access token expired, trying refresh...') - const refreshRes = await fetchWithCred(`${import.meta.env.VITE_API_BASE_URL}/api/refresh`, + const refreshRes = await fetchWithCred(`${import.meta.env.VITE_AUTH_SERVICE_URL}/api/refresh`, { method: 'POST', ...(csrfToken && { headers: { 'x-csrf-token': csrfToken }})