Search code examples
node.jsexpressnginxsession-cookiesnginx-reverse-proxy

http only cookie not working on express js with reverse proxy


Good day people i have a node js appplication which i use nginx as reverse proxy. whenever i set cookie it works but the httpOnly and secure flag is not ticked, please i need solution this is an image of the problemthe cookie when set on browser

my nginx configuration

app.set("trust proxy", 1);
app.use(helmet());
app.use(
  cors({
    credentials: true,
    origin: [
      "http://localhost:8080",
      "http://thegainer.xyz",
      "https://thegainer.xyz"
    ],
    exposedHeaders: ["set-cookie"]
  })
); 



  res.cookie("token", JSON.stringify(accessToken), {
secure: true,
httpOnly: true,
maxAge: 2592000000

});


Solution

  • oh sorry i got my answer.

    forgot to add app.set("trust proxy",1) on my frontend code this happened because I was not using nginx for static files but another nodejs server