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

669
Visualizações
HTTP cookies are not working for localhost subdomains

I have a node/express API that will create an HTTP cookie and pass it down to my React app for authentication. The setup was based on Ben Awad's JWT HTTP Cookie tutorial on Youtube if you're familiar with it. Everything works great when I am running the website on my localhost(localhost:4444). The issue I am now running into is that my app now uses subdomains for handling workspaces(similar to how JIRA or Monday.com uses a subdomain to specify a workspace/team). Whenever I run my app on a subdomain, the HTTP cookies stop working.

I've looked at a lot of threads regarding this issue and can't find a solution, no matter what I try, the cookie will not save to my browser. Here are the current things I have tried so far with no luck:

  • I've tried specifying the domain on the cookie. Both with a . and without
  • I've updated my host file to use a domain as a mask for localhost. Something like myapp.com:4444 which points to localhost:4444
  • I tried some fancy configuration I found where I was able to hide the port as well, so myapp.com pointed to localhost:4444.
  • I've tried Chrome, Safari, and Firefox
  • I've made sure there were no CORS issues
  • I've played around with the security settings of the cookie.
  • I also set up a ngrok server so there was a published domain to run in the browser

None of these attempts have made a difference so I am a bit lost at what to do at this point. The only other thing I could do is deploy my app to a proper server and just run my development off that but I really really don't want to do that, I should be able to develop from my local machine I would think.

My cookie knowledge is a bit bare so maybe there is something obvious I am missing?

This is what my setup looks like right now:

On the API I have a route(/refresh_token) that will create a new express cookie like so:

export const sendRefreshToken = (res: Response, token: string): void => {
  res.cookie('jid', token, {
    httpOnly: true,
    path: '/refresh_token',
  });
};

Then on the frontend it will essentially run this call on load:

fetch('http://localhost:3000/refresh_token', {
      credentials: 'include',
      method: 'POST'
    }).then(async res => {
      const { accessToken } = await res.json()
      setState({ accessToken, workspaceId })
      setLoading(false)
    })

It seems super simple to do but everything just stops working when on a subdomain. I am completely lost at this point. If you any ideas, that would be great!

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

if httpOnly is true, it won't be parsable through client side js. for working with cookies on subdomains, set domain as the main domain (xyz.com) an eg in BE:

res.cookie('refreshToken', refreshToken, {
  domain: authCookieDomain,
  path: '/',
  sameSite: 'None',
  secure: true,
  httpOnly: false,
  maxAge: cookieRefreshTokenMaxAgeMS
});

and on FE add withCredentials: true as axios options or credentials: include with fetch, and that should work

over 4 years ago · Santiago Trujillo 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