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

670
Vistas
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 Respuestas
Responde la pregunta

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