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

362
Views
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 answers
Answer question

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 Report
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!