Skip to content

Commit 40e7511

Browse files
Fix Vercel deployment
1 parent 6c11138 commit 40e7511

2 files changed

Lines changed: 43 additions & 245 deletions

File tree

‎src/App.jsx‎

Lines changed: 26 additions & 240 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
1-
// Put this file in: src/App.jsx (replaces your file)
2-
// Changes compared to your App.jsx:
3-
// 1) /interview/:id and /interview/:id/call now open the new in-app call page (InterviewCall),
4-
// for BOTH the user and the admin (it used to be user only, so the admin could never join)
5-
// 2) new admin routes: /admin/live (live interviews with Join button) and /admin/applications
1+
62
import { Routes, Route, Navigate } from "react-router-dom";
73

84
// Authentication & Protected Routes
9-
import ProtectedRoute from "./ProtectedRoute.jsx";
5+
// import ProtectedRoute from "./ProtectedRoute.jsx";
6+
7+
import ProtectedRoute from "./Protectedroute.jsx";
108

119
// Public Pages
1210
import Home from "./Home.jsx";
1311
import Login from "./Login.jsx";
1412
import SignUp from "./SignUp.jsx";
1513
import JobListing from "./JobListing.jsx";
16-
// import JobSearch from "./JobSearch.jsx";
1714
import Companies from "./Companies.jsx";
1815
import CompanyDetails from "./CompanyDetails.jsx";
1916
import HelpFAQ from "./HelpFAQ.jsx";
2017
import AboutUs from "./AboutUs.jsx";
2118
import ContactUs from "./ContactUs.jsx";
2219

23-
2420
// User Pages
2521
import ApplyJob from "./ApplyJob.jsx";
2622
import Dashboard from "./Dashboard.jsx";
@@ -29,9 +25,8 @@ import Notifications from "./Notifications.jsx";
2925
import Profile from "./Profile.jsx";
3026
import Settings from "./Settings.jsx";
3127
import MyInterviews from "./MyInterviews.jsx";
32-
// import InterviewRoom from "./InterviewRoom.jsx"; // replaced by InterviewCall (you can delete InterviewRoom.jsx later)
3328

34-
// Interview call page (used by the user AND the admin)
29+
// Interview Call
3530
import InterviewCall from "./InterviewCall.jsx";
3631

3732
// Admin Pages
@@ -44,7 +39,7 @@ export default function App() {
4439
return (
4540
<Routes>
4641

47-
{/* ================= PUBLIC ROUTES ================= */}
42+
{/* PUBLIC ROUTES */}
4843

4944
<Route path="/" element={<Home />} />
5045

@@ -54,8 +49,6 @@ export default function App() {
5449

5550
<Route path="/jobs" element={<JobListing />} />
5651

57-
{/* <Route path="/search" element={<JobSearch />} /> */}
58-
5952
<Route path="/companies" element={<Companies />} />
6053

6154
<Route
@@ -70,7 +63,7 @@ export default function App() {
7063
<Route path="/contact" element={<ContactUs />} />
7164

7265

73-
{/* ================= USER PROTECTED ROUTES ================= */}
66+
{/* USER PROTECTED ROUTES */}
7467

7568
<Route
7669
path="/apply/:id"
@@ -136,16 +129,28 @@ export default function App() {
136129
/>
137130

138131

139-
{/* ================= INTERVIEW CALL (user and admin) =================
140-
No role here on purpose: both the candidate and the recruiter (admin) must be able to open it.
141-
The backend (CallController) checks that the person really belongs to this interview. */}
132+
{/* INTERVIEW CALL - USER AND ADMIN */}
142133

143-
<Route path="/interview/:id" element={<InterviewCall />} />
134+
<Route
135+
path="/interview/:id"
136+
element={
137+
<ProtectedRoute>
138+
<InterviewCall />
139+
</ProtectedRoute>
140+
}
141+
/>
144142

145-
<Route path="/interview/:id/call" element={<InterviewCall />} />
143+
<Route
144+
path="/interview/:id/call"
145+
element={
146+
<ProtectedRoute>
147+
<InterviewCall />
148+
</ProtectedRoute>
149+
}
150+
/>
146151

147152

148-
{/* ================= ADMIN PROTECTED ROUTES ================= */}
153+
{/* ADMIN PROTECTED ROUTES */}
149154

150155
<Route
151156
path="/admin"
@@ -184,7 +189,7 @@ export default function App() {
184189
/>
185190

186191

187-
{/* ================= UNKNOWN ROUTES ================= */}
192+
{/* UNKNOWN ROUTES */}
188193

189194
<Route
190195
path="*"
@@ -194,222 +199,3 @@ export default function App() {
194199
</Routes>
195200
);
196201
}
197-
198-
199-
200-
201-
202-
// // Put this file in: src/App.jsx (replaces your file)
203-
// // Changes compared to your App.jsx:
204-
// // 1) ProtectedRoute now comes from RequireRole.jsx. It sends the person to /login when there is no token
205-
// // or the token has expired (before, an old login still opened the admin page with an empty list),
206-
// // and sends the wrong role (a USER on an admin page) to the home page.
207-
// // 2) /interview/:id and /interview/:id/call open the in-app call page (InterviewCall) for BOTH the
208-
// // user and the admin. They need a login, but no fixed role.
209-
// // 3) admin routes: /admin/live and /admin/applications
210-
// // Needs these files in src/: RequireRole.jsx and the newer api.js (from the careerhub-fix4 folder)
211-
// import { Routes, Route, Navigate } from "react-router-dom";
212-
213-
// // Authentication & Protected Routes
214-
// import ProtectedRoute from "./RequireRole.jsx"; // was ./ProtectedRoute.jsx
215-
216-
// // Public Pages
217-
// import Home from "./Home.jsx";
218-
// import Login from "./Login.jsx";
219-
// import SignUp from "./SignUp.jsx";
220-
// import JobListing from "./JobListing.jsx";
221-
// // import JobSearch from "./JobSearch.jsx";
222-
// import Companies from "./Companies.jsx";
223-
// import CompanyDetails from "./CompanyDetails.jsx";
224-
// import HelpFAQ from "./HelpFAQ.jsx";
225-
// import AboutUs from "./AboutUs.jsx";
226-
// import ContactUs from "./ContactUs.jsx";
227-
228-
// // User Pages
229-
// import ApplyJob from "./ApplyJob.jsx";
230-
// import Dashboard from "./Dashboard.jsx";
231-
// import Messages from "./Messages.jsx";
232-
// import Notifications from "./Notifications.jsx";
233-
// import Profile from "./Profile.jsx";
234-
// import Settings from "./Settings.jsx";
235-
// import MyInterviews from "./MyInterviews.jsx";
236-
// // import InterviewRoom from "./InterviewRoom.jsx"; // replaced by InterviewCall (you can delete InterviewRoom.jsx later)
237-
238-
// // Interview call page (used by the user AND the admin)
239-
// import InterviewCall from "./InterviewCall.jsx";
240-
241-
// // Admin Pages
242-
// import AdminDashboard from "./AdminDashboard.jsx";
243-
// import AdminJobs from "./admin/AdminJobs.jsx";
244-
// import AdminApplications from "./admin/AdminApplications.jsx";
245-
// import LiveInterviews from "./admin/LiveInterviews.jsx";
246-
247-
// export default function App() {
248-
// return (
249-
// <Routes>
250-
251-
// {/* ================= PUBLIC ROUTES ================= */}
252-
253-
// <Route path="/" element={<Home />} />
254-
255-
// <Route path="/login" element={<Login />} />
256-
257-
// <Route path="/signup" element={<SignUp />} />
258-
259-
// <Route path="/jobs" element={<JobListing />} />
260-
261-
// {/* <Route path="/search" element={<JobSearch />} /> */}
262-
263-
// <Route path="/companies" element={<Companies />} />
264-
265-
// <Route
266-
// path="/companies/:id"
267-
// element={<CompanyDetails />}
268-
// />
269-
270-
// <Route path="/help" element={<HelpFAQ />} />
271-
272-
// <Route path="/about" element={<AboutUs />} />
273-
274-
// <Route path="/contact" element={<ContactUs />} />
275-
276-
277-
// {/* ================= USER PROTECTED ROUTES ================= */}
278-
279-
// <Route
280-
// path="/apply/:id"
281-
// element={
282-
// <ProtectedRoute role="USER">
283-
// <ApplyJob />
284-
// </ProtectedRoute>
285-
// }
286-
// />
287-
288-
// <Route
289-
// path="/dashboard"
290-
// element={
291-
// <ProtectedRoute role="USER">
292-
// <Dashboard />
293-
// </ProtectedRoute>
294-
// }
295-
// />
296-
297-
// <Route
298-
// path="/messages"
299-
// element={
300-
// <ProtectedRoute role="USER">
301-
// <Messages />
302-
// </ProtectedRoute>
303-
// }
304-
// />
305-
306-
// <Route
307-
// path="/notifications"
308-
// element={
309-
// <ProtectedRoute role="USER">
310-
// <Notifications />
311-
// </ProtectedRoute>
312-
// }
313-
// />
314-
315-
// <Route
316-
// path="/profile"
317-
// element={
318-
// <ProtectedRoute role="USER">
319-
// <Profile />
320-
// </ProtectedRoute>
321-
// }
322-
// />
323-
324-
// <Route
325-
// path="/settings"
326-
// element={
327-
// <ProtectedRoute role="USER">
328-
// <Settings />
329-
// </ProtectedRoute>
330-
// }
331-
// />
332-
333-
// <Route
334-
// path="/my-interviews"
335-
// element={
336-
// <ProtectedRoute role="USER">
337-
// <MyInterviews />
338-
// </ProtectedRoute>
339-
// }
340-
// />
341-
342-
343-
// {/* ================= INTERVIEW CALL (user and admin) =================
344-
// No role on purpose: both the candidate and the recruiter (admin) must be able to open it.
345-
// Without a login the person is sent to /login and comes back here afterwards.
346-
// The backend (CallController) checks that the person really belongs to this interview. */}
347-
348-
// <Route
349-
// path="/interview/:id"
350-
// element={
351-
// <ProtectedRoute>
352-
// <InterviewCall />
353-
// </ProtectedRoute>
354-
// }
355-
// />
356-
357-
// <Route
358-
// path="/interview/:id/call"
359-
// element={
360-
// <ProtectedRoute>
361-
// <InterviewCall />
362-
// </ProtectedRoute>
363-
// }
364-
// />
365-
366-
367-
// {/* ================= ADMIN PROTECTED ROUTES ================= */}
368-
369-
// <Route
370-
// path="/admin"
371-
// element={
372-
// <ProtectedRoute role="ADMIN">
373-
// <AdminDashboard />
374-
// </ProtectedRoute>
375-
// }
376-
// />
377-
378-
// <Route
379-
// path="/admin/jobs"
380-
// element={
381-
// <ProtectedRoute role="ADMIN">
382-
// <AdminJobs />
383-
// </ProtectedRoute>
384-
// }
385-
// />
386-
387-
// <Route
388-
// path="/admin/applications"
389-
// element={
390-
// <ProtectedRoute role="ADMIN">
391-
// <AdminApplications />
392-
// </ProtectedRoute>
393-
// }
394-
// />
395-
396-
// <Route
397-
// path="/admin/live"
398-
// element={
399-
// <ProtectedRoute role="ADMIN">
400-
// <LiveInterviews />
401-
// </ProtectedRoute>
402-
// }
403-
// />
404-
405-
406-
// {/* ================= UNKNOWN ROUTES ================= */}
407-
408-
// <Route
409-
// path="*"
410-
// element={<Navigate to="/" replace />}
411-
// />
412-
413-
// </Routes>
414-
// );
415-
// }

‎src/Protectedroute.jsx‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
1+
12
import { Navigate, useLocation } from "react-router-dom";
23

3-
// Lets the page open only if a user is logged in (user + token).
4-
// Pass role="ADMIN" or role="USER" to also check the role.
54
export default function ProtectedRoute({ role, children }) {
65
const location = useLocation();
76

87
let user = null;
8+
99
try {
1010
user = JSON.parse(localStorage.getItem("loggedInUser"));
1111
} catch {
1212
user = null;
1313
}
14+
1415
const token = localStorage.getItem("token");
1516

1617
if (!user || !token) {
17-
return <Navigate to="/login" replace state={{ from: location }} />;
18+
return (
19+
<Navigate
20+
to="/login"
21+
replace
22+
state={{ from: location }}
23+
/>
24+
);
1825
}
1926

2027
if (role && user.role !== role) {
21-
return <Navigate to={user.role === "ADMIN" ? "/admin" : "/"} replace />;
28+
return (
29+
<Navigate
30+
to={user.role === "ADMIN" ? "/admin" : "/"}
31+
replace
32+
/>
33+
);
2234
}
2335

2436
return children;
25-
}
37+
}

0 commit comments

Comments
 (0)