I have nodejs application cookies working fine on localhost but when i deploy it on nginx live server cookie not set on client side. Please anyone to assist me on this matter. Below is the code am using to set up express session with cookie.
//express-session configurations
const storeOptions = {
host: process.env.DB_HOST,
port: process.env.DB_PORT,
user: process.env.DB_USER,
password: process.env.DB_PASS,
database: process.env.DB_NAME,
clearExpired: true,
}; //db store
const sessionStore = new MySQLStore(storeOptions);
const sessionOptions = {
key: process.env.SESSION_KEY,
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false,
store: sessionStore,
cookie: {
maxAge: 1000 * 60 * 60 * 12, //12hours
},
};
if (app.get("env") === "production") {
app.set("trust proxy", 1); // trust first proxy
sessionOptions.cookie.secure = true; // serve secure cookies
}
app.use(session(sessionOptions));
app.use(passport.initialize()); //initialize passport
app.use(passport.session()); //initialize session with passport
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
Hi @samunyi90,
Have you checked the logs?
The server-side generate a HMAC signature of the session ID which is used by session-express, if it hasn’t been created correctly the client-side doesn’t will work properly.
You can uses the debug-module to output debug messages:
I would be happy assist you,
Sergio Turpín
This comment has been deleted