refactor(lst): added side bar plus dummy menus

This commit is contained in:
2025-02-20 07:22:18 -06:00
parent 5f8943492e
commit 54b1b6081a
43 changed files with 1795 additions and 188 deletions

View File

@@ -5,21 +5,24 @@ import {sign, verify} from "jsonwebtoken";
*/
const fakeUsers = [
{id: 1, username: "admin", password: "password123"},
{id: 2, username: "user", password: "password123"},
{id: 3, username: "user2", password: "password123"},
{id: 1, username: "admin", password: "password123", role: "admin"},
{id: 2, username: "user", password: "pass", role: "user"},
{id: 3, username: "user2", password: "password123", role: "user"},
];
export function login(username: string, password: string): {token: string; user: {id: number; username: string}} {
export function login(
username: string,
password: string
): {token: string; user: {id: number; username: string; role: string}} {
const user = fakeUsers.find((u) => u.username === username && u.password === password);
if (!user) {
throw new Error("Invalid credentials");
}
// Create a JWT
const token = sign({userId: user?.id, username: user?.username}, process.env.JWT_SECRET, {
const token = sign({user}, process.env.JWT_SECRET, {
expiresIn: process.env.JWT_EXPIRES,
});
return {token, user: {id: user?.id, username: user.username}};
return {token, user: {id: user?.id, username: user.username, role: user.role}};
}

View File

@@ -40,7 +40,7 @@ session.openapi(route, async (c) => {
try {
const payload = await verify(token, JWT_SECRET);
console.log(payload);
return c.json({token});
return c.json({data: {token, user: payload.user}});
} catch (err) {
return c.json({error: "Invalid or expired token"}, 401);
}