feat : add signin ,signout, forgot password features
This commit is contained in:
21
src/App.jsx
21
src/App.jsx
@@ -1,16 +1,18 @@
|
||||
import React from 'react';
|
||||
import { BrowserRouter as Router, Routes, Route, Navigate } from 'react-router-dom';
|
||||
import { AuthProvider, useAuth } from './context/AuthContext';
|
||||
import { useAuthStore } from './store/authStore';
|
||||
import Sidebar from './components/Sidebar';
|
||||
import Navbar from './components/Navbar';
|
||||
import Login from './pages/Login';
|
||||
import Dashboard from './pages/Dashboard';
|
||||
import Transactions from './pages/Transactions';
|
||||
import Settings from './pages/Settings';
|
||||
import ForgotPassword from './pages/ForgotPassword';
|
||||
|
||||
// Protected Route Component
|
||||
const ProtectedRoute = ({ children }) => {
|
||||
const { isAuthenticated, loading } = useAuth();
|
||||
const isLoggedIn = useAuthStore((s) => s.isLoggedIn);
|
||||
const loading = useAuthStore((s) => s.loading);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
@@ -20,7 +22,7 @@ const ProtectedRoute = ({ children }) => {
|
||||
);
|
||||
}
|
||||
|
||||
return isAuthenticated ? children : <Navigate to="/login" />;
|
||||
return isLoggedIn ? children : <Navigate to="/login" />;
|
||||
};
|
||||
|
||||
// Main Layout Component
|
||||
@@ -58,6 +60,7 @@ const AppRoutes = () => {
|
||||
return (
|
||||
<Routes>
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route path="/forgot-password" element={<ForgotPassword />} />
|
||||
<Route
|
||||
path="/"
|
||||
element={
|
||||
@@ -96,13 +99,11 @@ const AppRoutes = () => {
|
||||
// Main App Component
|
||||
const App = () => {
|
||||
return (
|
||||
<AuthProvider>
|
||||
<Router>
|
||||
<div className="App">
|
||||
<AppRoutes />
|
||||
</div>
|
||||
</Router>
|
||||
</AuthProvider>
|
||||
<Router>
|
||||
<div className="App">
|
||||
<AppRoutes />
|
||||
</div>
|
||||
</Router>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user