deleted api post request and replaced with self written function from database.js.
Also deleted login-auth from docker compose, but not the folder (we can later work on this again).
This commit is contained in:
@@ -35,22 +35,22 @@ services:
|
|||||||
- ./shared:/shared
|
- ./shared:/shared
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
login-auth:
|
# login-auth:
|
||||||
container_name: login-auth
|
# container_name: login-auth
|
||||||
build: ./login-auth_backend
|
# build: ./login-auth_backend
|
||||||
ports:
|
# ports:
|
||||||
- "4002:4002"
|
# - "4002:4002"
|
||||||
environment:
|
# environment:
|
||||||
DB_HOST: mysql
|
# DB_HOST: mysql
|
||||||
DB_USER: root
|
# DB_USER: root
|
||||||
DB_PASSWORD: D7Ze0lwV9hMrNQHdz1Q8yi0MIQuOO8
|
# DB_PASSWORD: D7Ze0lwV9hMrNQHdz1Q8yi0MIQuOO8
|
||||||
DB_NAME: login_page
|
# DB_NAME: login_page
|
||||||
depends_on:
|
# depends_on:
|
||||||
- mysql
|
# - mysql
|
||||||
volumes:
|
# volumes:
|
||||||
- ./login-auth_backend:/login-auth_app
|
# - ./login-auth_backend:/login-auth_app
|
||||||
- ./shared:/shared
|
# - ./shared:/shared
|
||||||
restart: unless-stopped
|
# restart: unless-stopped
|
||||||
|
|
||||||
mysql:
|
mysql:
|
||||||
container_name: mysql-db
|
container_name: mysql-db
|
||||||
|
@@ -33,27 +33,15 @@ app.get("/", (req, res) => {
|
|||||||
res.render("index.ejs", { error: null });
|
res.render("index.ejs", { error: null });
|
||||||
});
|
});
|
||||||
|
|
||||||
app.post("/login", (req, res) => {
|
app.post("/login", async (req, res) => {
|
||||||
const { username, password } = req.body;
|
const { username, password } = req.body;
|
||||||
const apiUrl = "http://localhost:4002/login";
|
loginUser(username, password).then((result) => {
|
||||||
|
if (result.success === true) {
|
||||||
axios
|
res.render("userView.ejs");
|
||||||
.post(apiUrl, { username, password })
|
} else {
|
||||||
.then(function (response) {
|
res.render("index.ejs", { error: result.message });
|
||||||
if (response.data.loginQuery) {
|
}
|
||||||
// If login is successful, redirect to the dashboard
|
});
|
||||||
res.render("userView.ejs");
|
|
||||||
} else {
|
|
||||||
// If login fails, render the login page with an error message
|
|
||||||
res.status(404).render("index.ejs", { error: response.data.message });
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(function (error) {
|
|
||||||
console.error("Error during login:", error);
|
|
||||||
res
|
|
||||||
.status(500)
|
|
||||||
.render("index.ejs", { error: "An error occurred during login." });
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// error handling code
|
// error handling code
|
||||||
|
Reference in New Issue
Block a user