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

386
Vistas
I can't get my httpOnly cookie from my post request using axios

I am having an issue where I am not able to grab my cookies from my node.js backend. Below is my current code and when I console.log(req.cookies) It returns [Object: null prototype] {}. I had a similar issue in the past and the way I fixed that was just by adding "withCredentials: true" but since I already have that on my axios post request I don't believe that to be the issue.

Front-end

  const save = async () => {
    if (loggedInCookie) {
        await axios.post('http://localhost:5000/savelisting', {
            withCredentials: true,
            link: link,
            car: car,
            price: price,
            picture: picture,
            timeleft: timeleft,
            site: site,
            milage: milage,
            location: location,
            trans: trans
        });

    } else {
        console.log("please login to save this listing")
    };

};

Backend

app.post('/savelisting', async (req, res) => {
    console.log(req.cookies);

    try {
    var jwtToken = await req.cookies.AccessToken;
    console.log(jwtToken);

    // Grooms cookie
    jwtToken = jwtToken
                    .split('; ')
                    .find(row => row.startsWith('AccessToken='))
                    .split('=')[1];


    const decoded = jwt.verify(jwtToken, process.env.TOKEN_KEY);
    var userId = decoded.id
    console.log(userId) 
 
    const link = req.body.link;
    const car = req.body.car;
    const price = req.body.price;
    const picture = req.body.picture;
    const timeleft = req.body.timeleft;
    const site = req.body.site;
    const milage = req.body.milage;
    const location = req.body.location;
    const trans = req.body.trans;

    } catch(err) {
        console.log(err)
    };
    res.status(200).send();
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You are sending the withCredentials setting as part of the data to your API. It should be passed as an option to axios:

axios.post(
    'http://localhost:5000/savelisting',
    {    
        link: link,
        car: car,
        ...
    },
    {
        withCredentials: true
    }
)
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