- Added `jose` library for JWT token generation and verification. - Implemented login functionality with token storage using cookies. - Created `HeaderAdmin` component for admin panel with login/logout capabilities. - Developed `LoginForm` component for user authentication. - Added `Table` component to display data with caching from localStorage. - Introduced `SubHeaderAdmin` for additional admin actions. - Enhanced `database.js` with functions for admin login and fetching table data. - Updated `server.js` to handle new routes for login and table data retrieval. - Modified `package.json` and `package-lock.json` to include new dependencies.
30 lines
683 B
TypeScript
30 lines
683 B
TypeScript
import "../App.css";
|
|
import React, { useState } from "react";
|
|
import HeaderAdmin from "./HeaderAdmin";
|
|
import Table from "./Table";
|
|
import Cookies from "js-cookie";
|
|
|
|
const Admin: React.FC = () => {
|
|
// Keep token in state so UI updates immediately after login without reload
|
|
const [token, setToken] = useState<string | null>(
|
|
() => Cookies.get("token") ?? null
|
|
);
|
|
|
|
return (
|
|
<>
|
|
<HeaderAdmin
|
|
token={token}
|
|
onLoginSuccess={(t) => setToken(t)}
|
|
onLogout={() => setToken(null)}
|
|
/>
|
|
{token ? (
|
|
<Table />
|
|
) : (
|
|
<div className="p-4">Please log in as an admin.</div>
|
|
)}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default Admin;
|