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

208
Visualizações
express session is not persistent when server deployed to heroku

I built a simple user authentication app with React, node and Passport JS. When on localhost, it successfully stores the session and persist the user but after deploying on heroku it doesn't persist the session.

I checked networks tab and found that sameSite attribute is by default set to lax and if client wants to get cross site cookies it should be set to none and must have secure attribute set. But when I set sameSite to none and secure to true, client don't get the cookie from the server (e.g set-cookie header is not present in response)enter image description here.

I don't know where am I doing wrong.

This is my Server JS

// Middlewares
app.use(express.json());

app.use(
  cors({
    origin: "https://authclient.netlify.app",
    credentials: true,
  })
);

app.use(
  session({
    secret: "secret",
    resave: true,
    saveUninitialized: true,
    cookie: {
      sameSite: "none",
      secure: true,
    },
    store: MongoStore.create({ mongoUrl: dbURI }),
  })
);
app.use(cookieParser("secret"));

app.use(passport.initialize());
app.use(passport.session());
require("./passportConfig")(passport);
//______________________________________

//Routes
app.post("/login", (req, res, next) => {
  passport.authenticate("local", (err, user, info) => {
    if (err) throw err;
    if (!user) res.send(info.message);
    else {
      req.logIn(user, (err) => {
        if (err) throw err;
        res.send("Logged In!");
      });
    }
  })(req, res, next);
});

about 4 years ago · Juan Pablo Isaza
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