I wrote a code for login system (backend) which checks whether the username and password are valid or not. Everything is working but I don't know how to do automate redirect to /dashboard. Client side is running on Port 3000, and server on Port 3001 and I am getting error because script finding the /dashboard on localhost:3001. Can anyone help me?
app.post("/login", (req, res) => {
// Capture the input fields
const username = req.body.username;
const password = req.body.password;
// Ensure the input fields exists and are not empty
if (username && password) {
// Execute SQL query that'll select the account from the database based on the specified username and password
db.query(
"SELECT * FROM users WHERE username = ? AND password = ?",
[username, password],
function (error, results, fields) {
// If the account exists
if (results.length > 0) {
console.log('Valid')
} else {
console.log('Invalid')
}
res.end();
}
);
} else {
res.send("Please enter Username and Password!");
res.end();
}
});