Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

203
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda