File size: 1,830 Bytes
90f0c0b
b811a8f
90f0c0b
 
b811a8f
 
 
 
 
 
90f0c0b
 
b811a8f
90f0c0b
c1209d2
a3b81fa
 
90f0c0b
c1209d2
76a77bc
2636d69
90f0c0b
 
 
 
 
 
 
 
 
 
 
 
b811a8f
90f0c0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2636d69
90f0c0b
 
 
 
 
b811a8f
90f0c0b
 
2636d69
90f0c0b
2636d69
90f0c0b
b811a8f
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import React from "react";
import { BrowserRouter as Router, Routes, Route, Navigate } from "react-router-dom";

import Home from "./pages/home";
import Dashboard from "./pages/dashboard";
import Notes from "./pages/note";
import AIInterview from "./pages/AiInterview";
import Quize from "./pages/quize";
import Sidebar from "./components/dashboard/Sidebar";

import { AuthProvider, useAuth } from "./components/context/AuthContext";
import ProtectedRoute from "./routes/ProtectedRoute";

const DashboardLayout = () => {
  // 1. Retrieve both logout and username from the AuthContext

  return (
    <div className="flex h-screen bg-gray-100">
      {/* 2. Pass the retrieved username prop to the Sidebar */}
      <Sidebar/>

      <main className="flex-1 overflow-y-auto">
        <Routes>
          <Route path="/dashboard" element={<Dashboard />} />
          <Route path="/notes" element={<Notes />} />
          <Route path="/AIInterview" element={<AIInterview />} />
          <Route path="/quize" element={<Quize />} />
          <Route path="*" element={<Navigate to="/dashboard" />} />
        </Routes>
      </main>
    </div>
  );
};

const App: React.FC = () => {
  return (
    <AuthProvider>
      <Router>
        <Routes>
          {/* Public Home */}
          <Route path="/" element={<HomeWrapper />} />

          {/* Protected all dashboard routes */}
          <Route
            path="/*"
            element={
              <ProtectedRoute>
                <DashboardLayout />
              </ProtectedRoute>
            }
          />

        </Routes>
      </Router>
    </AuthProvider>
  );
};

const HomeWrapper = () => {
  const { isAuthenticated, login } = useAuth();

  if (isAuthenticated) return <Navigate to="/dashboard" replace />;

  return <Home onLogin={login} />;
};

export default App;