I am getting error code 400 when I try to login through my frontend. When I see my heroku logs I think it send the query to the database but doesn't gets the result back instead gets an error.
This only happens when the server is running for quite a time and is resolved if I just restart the heroku server.
Code for my login endpoint is:
const Login = (req, res) => {
if (!req.session.user) {
try {
const user = req.body;
let sql = `SELECT * FROM users WHERE type_id=?;`;
db.query(sql, user.type_id, async (err, result) => {
if (err) res.status(400).send(err);
if (result[0]) {
if (await argon2.verify(result[0].password, user.password)) {
req.session.user = {
type: result[0].type,
id: result[0].UserId,
name: result[0].full_name,
typeId: result[0].type_id,
};
res.status(200).send("logged in");
} else res.send("wrong password");
} else res.send("invalid id / user doesnot exist sign up first");
});
} catch {
res.status(500).send(null);
}
} else res.send("already logged in");
};
This happens for my root endpoint also :
app.get("/", (req, res) => {
try {
const sql = "SELECT * FROM users;";
db.query(sql, (err, result) => {
if (err) res.send(err);
res.send(result);
});
console.log(req.session);
} catch {
res.status(500).send(null);
}
});
Here when I go to the root from my browser it shows
{"fatal":true}
Again from the heroku logs all I can make out of it is that whenever the query is sent to the database it send back error.