feat: add authentication and admin features
- 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.
This commit is contained in:
@@ -2,7 +2,7 @@ import mysql from "mysql2";
|
||||
import dotenv from "dotenv";
|
||||
dotenv.config();
|
||||
|
||||
// Create a MySQL connection pool using environment variables for configuration
|
||||
// Ein einzelner Pool reicht; der zweite Pool benutzte fälschlich DB_TABLE als Datenbank
|
||||
const pool = mysql
|
||||
.createPool({
|
||||
host: process.env.DB_HOST,
|
||||
@@ -32,3 +32,21 @@ export async function query(params) {
|
||||
return { success: false };
|
||||
}
|
||||
}
|
||||
|
||||
export async function loginAdmin(username, password) {
|
||||
const [rows] = await pool.query(
|
||||
"SELECT * FROM admin_user WHERE username = ? AND password = ?",
|
||||
[username, password]
|
||||
);
|
||||
if (rows.length > 0) return { success: true };
|
||||
return { success: false };
|
||||
}
|
||||
|
||||
export async function getTableData() {
|
||||
const [result] = await pool.query("SELECT * FROM lose");
|
||||
|
||||
if (result.length > 0) {
|
||||
return { success: true, data: result };
|
||||
}
|
||||
return { success: false };
|
||||
}
|
||||
|
Reference in New Issue
Block a user