added Login function.
Also added user table but insecure. (In the next time, going to secure the get all users.) Also noted out the react frontend from the docker compose file - just for development purposes. I have also created some utils to logout the user and to get all users.
This commit is contained in:
@@ -24,9 +24,9 @@ app.post("/api/login", async (req, res) => {
|
||||
loginUser(req.body.username, req.body.password)
|
||||
.then((result) => {
|
||||
if (result.success) {
|
||||
res.status(200).json(result);
|
||||
res.status(200).json(result, { message: "Login successful" });
|
||||
} else {
|
||||
res.status(401).json(result);
|
||||
res.status(401).json(result, { message: "Invalid credentials" });
|
||||
}
|
||||
})
|
||||
.catch((err) => {
|
||||
@@ -37,6 +37,17 @@ app.post("/api/login", async (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
app.get("/api/getAllUsers", async (req, res) => {
|
||||
getAllUsers()
|
||||
.then((users) => {
|
||||
res.status(200).json(users);
|
||||
})
|
||||
.catch((err) => {
|
||||
console.error("Error fetching users:", err);
|
||||
res.status(500).json({ success: false, message: "Internal server error" });
|
||||
});
|
||||
});
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Express backend server is running at http://localhost:${port}`);
|
||||
});
|
||||
|
Reference in New Issue
Block a user