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

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