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

101
Visualizações
How to locally test set Cookies with the Same Origine Policy

I have a problem when testing my web app locally. I set cookies in a request response (here is how) :

const token = createToken(user._id);
res.cookie("jwt", token, { httpOnly: true, maxAge: maxAge,  });
res.status(201).json({ user: user._id });
return res;

But I encounter an error about Same domain Policy when executing the following request in the React Client:

axios.post(`${process.env.REACT_APP_API_URL}api/user/login`, {
                email: email,
                password: password,
            },
            {
                withCredentials: true
            })
            .then((res) => {
                if (res.data.errors) {
                    //Show errors
                }
            })
            .catch((err) => {
                console.log(err);
            }); 

I tried to execute it with the parameter withCredentials : false

The request works but the cookie is not stored But I have set-Cookie in the response of my request

And this is my CORS options :

const corsOptions = {
    origin: process.env.CLIENT_URL,
    credentials: true,
    allowedHeaders: ["sessionId", "Content-Type"],
    exposedHeaders: ["sessionId"],
    methods: "GET,HEAD,PUT,PATCH,POST,DELETE",
    preflightContinue: false
};
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I remplace my cors options by :

const corsOptions = {origin: process.env.CLIENT_URL,credentials: true};

and add :

app.options('*', cors(corsOptions));

and now it's working

about 4 years ago · Santiago Gelvez 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