app.post('/login', (request, response) => {
console.log('request came in');
const values = [request.body.email];
pool.query('SELECT * from users WHERE email=$1', values, (error, result) => {
console.log('Error executing query', error.stack);
response.status(503).send(result.rows);
if (result.rows.length === 0) {
// we didnt find a user with that email.
// the error for password and user are the same. don't tell the user which error they got for security reasons, otherwise people can guess if a person is a user of a given service.
response.status(403).send('sorry!');
const user = result.rows[0];
if (user.password === request.body.password) {
response.cookie('loggedIn', true);
response.send('logged in!');
// the error for password and user are the same. don't tell the user which error they got for security reasons, otherwise people can guess if a person is a user of a given service.
response.status(403).send("sorry!");