diff --git a/app-frontend/employer-panel/.env b/app-frontend/employer-panel/.env index 2b00470c9..31d35cbf7 100644 --- a/app-frontend/employer-panel/.env +++ b/app-frontend/employer-panel/.env @@ -1,2 +1,2 @@ -REACT_APP_API_BASE_URL=http://localhost:5000/api/v1 +REACT_APP_API_BASE_URL=http://localhost:5001/api/v1 NODE_ENV=development diff --git a/app-frontend/employer-panel/src/pages/GuardProfile.js b/app-frontend/employer-panel/src/pages/GuardProfile.js index 701bd2dd5..4eb9c78e5 100644 --- a/app-frontend/employer-panel/src/pages/GuardProfile.js +++ b/app-frontend/employer-panel/src/pages/GuardProfile.js @@ -1,5 +1,6 @@ import React, { useState, useRef, useEffect } from "react"; import { useNavigate } from "react-router-dom"; +import http from "../lib/http"; // ❌ removed local dummy guardData @@ -43,21 +44,7 @@ function GuardProfiles() { setLoading(true); // NEW setError(""); // NEW - const token = localStorage.getItem("token"); // NEW (if you use JWT) - const res = await fetch(`${API_BASE}/api/v1/users/guards`, { - method: "GET", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${token}`, // ✅ send token - } -}); // NEW - - if (!res.ok) { // NEW - const text = await res.text().catch(() => ""); // NEW - throw new Error(text || `Request failed (${res.status})`); // NEW - } // NEW - - const data = await res.json(); // NEW + const { data } = await http.get("/users/guards"); // NEW // Accept both shapes: array OR {guards:[...]} ----------------- // NEW const list = Array.isArray(data) ? data : Array.isArray(data?.guards) ? data.guards : []; // NEW @@ -82,9 +69,15 @@ function GuardProfiles() { })); // NEW if (mounted) setGuards(normalized); // NEW - } catch (e) { // NEW - if (mounted) setError(e.message || "Failed to fetch guards"); // NEW - } finally { // NEW + } catch (e) { + if (!mounted) return; + + if (e.response?.status === 403) { + setError("You don’t have permission to view guards yet."); + } else { + setError(e.response?.data?.message || e.message || "Failed to fetch guards"); + } +} finally { // NEW if (mounted) setLoading(false); // NEW } // NEW })(); // NEW @@ -162,7 +155,8 @@ function GuardProfiles() { {/* NEW: loading / error / empty states */} {loading &&
Loading guards…
} {/* NEW */} {!loading && error && ( /* NEW */ -Failed to load: {error}
/* NEW */ +{error}
/* NEW */ + )} {!loading && !error && guards.length === 0 && ( /* NEW */No guards found.
/* NEW */ @@ -240,4 +234,4 @@ function GuardProfiles() { ); } -export default GuardProfiles; \ No newline at end of file +export default GuardProfiles; diff --git a/docker-compose.yml b/docker-compose.yml index 4cd4d3b14..489ddbc69 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,7 +4,7 @@ services: context: ./app-backend container_name: secureshift-backend ports: - - "5000:5000" + - "5001:5000" env_file: - ./app-backend/.env depends_on: @@ -46,4 +46,4 @@ volumes: mongo-data: networks: - secureshift: \ No newline at end of file + secureshift: