Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
Not saved cookie in chrome with mysql and express js

I am using react in the frontend and express and MySQL in the backend. When I user trying to log in then the cookie is not saved in the client browser. I am was find
this solution on google but I am not found it. Advanve thanks.

const jwt = require("jsonwebtoken");
const connection = require("../config/db");

const signin = async (req, res) => {
  const { email, password } = req.body;

  if ((email, password)) {
    const sqlGet = "select * from users where email=?";
    connection.query(sqlGet, email, (err, result) => {
      if (err) {
        res.send(err);
      }
      if (result[0]) {
        const sqlPassEmail =
          "select * from users where email=? and password=SHA(?)";
        connection.query(sqlPassEmail, [email, password], (err2, result2) => {
          if (err2) {
            res.send(err2);
          }
          if (result2[0]) {
            const userObject = {
              username: result2[0].username,
              email: result2[0].email,
            };

            // generate token
            const token = jwt.sign(userObject, process.env.JWT_SECRET, {
              expiresIn: process.env.JWT_EXPIRY,
            });

            // set cookie
            res.cookie(process.env.COOKIE_NAME, token, {
              maxAge: process.env.JWT_EXPIRY,
              httpOnly: true,
              signed: true,
            });

            

            res.status(200).json(result2[0]);
          } else {
            res.status(404).send("Worng password!");
          }
        });
      } else {
        res.status(404).send("Email is not valid!");
      }
    });
  } else {
    res.status(404).send("Please enter email and password!");
  }
};

module.exports = {
  signin,
};
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!