I want to check username/password with a post request using axios like this :
function axiosCall() {
axios.post('/login', {
username: document.getElementById("username").innerText,
password: document.getElementById("password").innerText
})
.then(function (problem) {
if (problem.toString() === "username") {
lespanUsername.innerHTML = "Pseudo incorrect !";
} else if (problem.toString() === "password") {
lespanPassword.innerHTML = "Votre mot de passe est incorrect !";
}
})
}
But my express post :
app.post('/login', urlEncodedParser, (req, res) => {
let username = req.body.username;
let password = req.body.password;
if (users.existUser(username)) {
if (users.validUser(username, password) === true) {
res.status(200)
res.redirect("/");
} else {
res.status(401)
res.send("password")
}
} else {
res.status(401)
res.send("username")
}
});
Sending html instead of a variable and reloading my page. :
Does anyone have an answer, I haven't found a solution despite a lot of searching. The send("username") works on the examples I found online. Thanks in advance !