Add login, save and invite features

This commit is contained in:
thoenykaroli committed 2026-04-10 22:50:25 +02:00
1 parent 66c51e9238
commit 3208977b9a
7 files changed
+422 -15

No files matched your search

+39 -1
View File
@@ -10,7 +10,7 @@ app.use(cors());
app.use(express.json());
// =========================
// ROOT (optional)
// ROOT
// =========================
app.get("/", (req, res) => {
res.send("Encore API is running");
@@ -121,6 +121,44 @@ app.post("/api/invitation/:id/decline", (req, res) => {
res.json(inv);
});
let users = [];
// CREATE USER
app.post("/api/user", (req, res) => {
const { username } = req.body;
if (!username) {
return res.status(400).json({ message: "Username required" });
}
if (users.find(u => u.username === username)) {
return res.status(400).json({ message: "User exists" });
}
const password = "1234";
const user = { username, password };
users.push(user);
res.json({ name: username, password });
});
// LOGIN
app.get("/api/user", (req, res) => {
const username = req.header("X-Username");
const password = req.header("X-Password");
const user = users.find(
u => u.username === username && u.password === password
);
if (!user) return res.sendStatus(401);
res.sendStatus(201);
});
// =========================
// START SERVER
// =========================