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

291
Visualizações
How do I remove cookies from nextjs external API calls

I am using nextjs server side apis to send external api calls. Using Axios as the httpClient. Not matter what i do, I can find no successful way to remove all cookies from my API calls which don't need cookies. They need to be removed because now the cookies in users browsers are bloating and causing problems on the calls.

Here is what I am doing:

export const queryData = (caller: string, enabled = true) => {
  return useQuery(
    ['queryData ', caller],
    async () => {
      const { data } = await httpClient.get('/api/proxy/getData'{
        headers: {
          'Cookie': "cookiename=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;"
        }
      });
      return data;
    },
    { ...useQueryOptions, enabled }
  );
};

then in the next.config.js, I am sending any calls to /api/proxy/* to the appropriate external api gateway, as in


module.exports = (phase) => {

    return {
        async rewrites() {
            return [
                {
                    source: `/api/proxy/:path*`,
                    destination: `${externalApiGatewayUrl}/:path*`
                }
            ];
        },

The calls all flow through correctly and have the proper query params and headers, but unfortunately, I can't figure out how to get the cookies only removed from the call.

I tried the above 'Cookie': "cookiename=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;" and it doesn't work to remove the cookies. I get the following error in the console:

Refused to set unsafe header "Cookie"

Does anyone have an actual working example of properly removing cookies from Nextjs server side API calls to external APIs?

I only need to (or want to) do this on these server side calls to external APIs. NextJS examples would be helpful. General javascript isn't helpful if it is not within the context of NextJS.

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

0

Just set the expires parameter to a past date: document.cookie = "username=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";

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