Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

370
Visualizações
Cookies are not received in the browser on localhost when handling a response from backend (express js)

I am having some trouble with implementing authorization cookies.

When I make a GET request to my api (which is running on port 8080) from my react frontend (which is running on port 3000), the cookies which I set with express are not received in the frontend.

I'm implementing a subdomain per client type of application, and the cookies are rightfully received on the normal "localhost". However, when I try to use like example.localhost, the cookies are not received at all.

I tried to do it both with axios and normal fetches, and I just can't seem to get it to work.

I used Same-Site, Secure etc and set credentials to true both in CORS and Axios.

Here are a couple snippets:

app.get('/api/dashboard/overview', (req, res) => {
    res.cookie("test", "test", {httpOnly: false}); //Already tried Secure etc
    res.send('Cookie was set!');
});
getRequest('/dashboard/overview').then(response => {
     console.log(response.data);
     return response;
});
export function getRequest(url) {
    return axios.get(apiUrl + url, {withCredentials: true, headers: { crossDomain: true, 'Content-Type': 'application/json' }});
}

I think the problem lies in the subdomain.localhost stuff, but sometimes the cookies do not load on normal localhost either.

I already tried to add a domain to vhosts, but it did not work either.

Hope one of you guys could help!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If your web server is running on localhost:8080, try to add this property to cors object. Might can do the trick.

origin: 'http://localhost:8080'
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda