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

135
Vistas
How do I set a header in the login route so the browser remembers who is logged in

I've created a user login back end and everything works fine, but when I log in to a user detail, despite being correct, I'm unable to explore other routes because the user isn't authorized. how do I save the access token to the browser so it remembers? This is the login route below.

router.post("/login", async (req, res) => {
try {
    const oneUser = await users.findOne({
        username: req.body.username,
    });

    if (!oneUser) {
        return res.status(500).json("User is not in the database");
    }

    const oPassword = cj.AES.decrypt(
        oneUser.password,
        process.env.pass
    ).toString(cj.enc.Utf8);

    if (oPassword !== req.body.password) {
        return res.status(500).json("Password is incorrect");
    }

    const accessToken = jwt.sign(
        {
            id: oneUser._id,
            isAdmin: oneUser.isAdmin,
        },
        process.env.jwtToken,
        { expiresIn: "300" }
    );

    const { password, ...others } = oneUser._doc;
    res.status(200).json({ ...others, accessToken });

} catch (err) {
    res.status(500).json(err);
}

});

I saw something like this on the net.

res.header("token", accessToken)
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

for this you can save a session for that user or response the token and save that to the client browser cookies or session store.

for setting session at node js app checkout link below https://www.npmjs.com/search?q=session

about 4 years ago · Juan Pablo Isaza Denunciar
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