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

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

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