fixed sidebar and backend for sidebar

This commit is contained in:
2025-08-19 14:00:00 +02:00
parent 298bc81435
commit 06f84cddc4
4 changed files with 28 additions and 10 deletions

View File

@@ -7,7 +7,10 @@ const router = express.Router();
router.post("/login", async (req, res) => {
const result = await loginFunc(req.body.username, req.body.password);
if (result.success) {
const token = await generateToken({ username: req.body.username });
const token = await generateToken({
username: result.data.username,
role: result.data.role,
});
res.status(200).json({ message: "Login successful", token });
} else {
res.status(401).json({ message: "Invalid credentials" });
@@ -15,7 +18,8 @@ router.post("/login", async (req, res) => {
});
router.get("/items", authenticate, async (req, res) => {
const result = await getItemsFromDatabase();
console.log(req);
const result = await getItemsFromDatabase(req.user.role);
if (result.success) {
res.status(200).json(result.data);
} else {