By samunyi90
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
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
This comment has been deleted
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:
DEBUG=express-mysql-session* node your-app.js
I would be happy assist you,
Sergio Turpín
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.