Adding login auth
This commit is contained in:
+31
-11
@@ -1,17 +1,37 @@
|
||||
import React from 'react';
|
||||
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
|
||||
import Login from './pages/Login';
|
||||
import Register from './pages/Register';
|
||||
import React from "react";
|
||||
import { BrowserRouter as Router, Routes, Route, useNavigate } from "react-router-dom";
|
||||
import Login from "./pages/Login";
|
||||
import Register from "./pages/Register";
|
||||
import { useAuth } from "./AuthContext";
|
||||
|
||||
const App = () => {
|
||||
const { isAuthenticated, logout } = useAuth();
|
||||
|
||||
return (
|
||||
<Router>
|
||||
<Routes>
|
||||
<Route path="/" element={<Login />} />
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route path="/register" element={<Register />} />
|
||||
</Routes>
|
||||
</Router>
|
||||
<div style={{ height: "100vh", display: "flex", flexDirection: "column" }}>
|
||||
{/* Logout button */}
|
||||
{isAuthenticated && (
|
||||
<div style={{ display: "flex", justifyContent: "flex-end", padding: "1rem" }}>
|
||||
<button onClick={logout}>Logout</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Centered content */}
|
||||
<div
|
||||
style={{
|
||||
flex: 1,
|
||||
display: "flex",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
<Routes>
|
||||
<Route path="/" element={<Login />} />
|
||||
<Route path="/login" element={<Login />} />
|
||||
<Route path="/register" element={<Register />} />
|
||||
</Routes>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user