Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app-frontend/employer-panel/.env
Original file line number Diff line number Diff line change
@@ -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
34 changes: 14 additions & 20 deletions app-frontend/employer-panel/src/pages/GuardProfile.js
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -162,7 +155,8 @@ function GuardProfiles() {
{/* NEW: loading / error / empty states */}
{loading && <p style={{ textAlign: "center" }}>Loading guards…</p>} {/* NEW */}
{!loading && error && ( /* NEW */
<p style={{ textAlign: "center", color: "#b00020" }}>Failed to load: {error}</p> /* NEW */
<p style={{ textAlign: "center", color: "#b00020" }}>{error}</p> /* NEW */

)}
{!loading && !error && guards.length === 0 && ( /* NEW */
<p style={{ textAlign: "center" }}>No guards found.</p> /* NEW */
Expand Down Expand Up @@ -240,4 +234,4 @@ function GuardProfiles() {
);
}

export default GuardProfiles;
export default GuardProfiles;
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
context: ./app-backend
container_name: secureshift-backend
ports:
- "5000:5000"
- "5001:5000"
env_file:
- ./app-backend/.env
depends_on:
Expand Down Expand Up @@ -46,4 +46,4 @@ volumes:
mongo-data:

networks:
secureshift:
secureshift:
Loading