Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

562
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda