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

557
Views
why is my cookie not saving on the browser?

I have this block of code and when a user login, it should set the "access_token" cookie to a token, but when i check the browser application cookie, i see nothing and user is unauthenticated.

const login = async (req, res) => {
  try {
    const oneUser = await Users.findOne({ username: req.body.username });
    if (!oneUser) {
      return res.status(403).json("No such user in the database");
    }

    const isPassword = await bcryptjs.compare(req.body.password, oneUser.password);

    if (!isPassword) {
      return res.status(500).json("Password is incorrect");
    }

    const token = jwt.sign(
      {
        id: oneUser._id,
        isAdmin: oneUser.isAdmin,
      },
      process.env.jwt,
    );

    const { password, ...others } = oneUser._doc;
    res
      .cookie("access_token", token)
      .status(200)
      .json({ ...others });
  } catch (err) {
    res.status(500).json(err);
  }
};

in the routes auth file i call it like so


    router.post("/login", login);

then in my index.html file, i linked the routes up.

    app.use("/api/auth", authRoute);

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!