this is my function for taking input for login and sending it to backend for authentication and redirection to a particular page:
const onSubmit = async (data) => {
try {
const response = await fetch("http://localhost:3000/login", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
credentials: 'include'
});
if (response.ok) {
window.location.href = ("http://localhost:3001/");
} else {
console.error("Login failed");
}
} catch (error) {
console.error("Error:", error);
}
};
this is the server code for login authentication:
app.post('/login',
passport.authenticate('local', { failureRedirect: '/login'}, console.log("login failed")),
function(req, res) {
res.status(200).json({ isAuthenticated: true }, console.log(" login success"));
}
);
I dont know why i am getting a “GET http://localhost:3000/login 404 (Not Found)” error in the client side console due to which user is not able to login. All the requests which i am hitting are POST.
Tried to ask chatgpt but it didn’t help me.
Any kind of suggestions will be very grateful.
Thor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.