By yabis0109
I have deployed a node express server on digital ocean. However, it won’t create the session once it’s deployed. I added a store to prevent memory leak and initialized app.set('trust proxy', 1), before the session. I am creating a user for the session once the user is authenticated. The snippet below shows the configuration for the session.
app.use(
session({
key: "userid",
secret: "subscribe",
resave: false,
saveUninitialized: false,
store: sessionStore,
cookie: {
expires: 60000 * 60,
domain: ".section-webapp-y793v.ondigitalocean.app"
}
})
)
app.get("/login", (req, res) => {
if (req.session.user) {
res.send({ loggedIn: true, user: req.session.user })
} else {
res.send({ loggedIn: false })
}
}
)
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!
Heya,
DigitalOcean’s App Platform provides a fully managed environment for deploying applications. However, the issue you’re experiencing seems related to how Express and session handling works in general, rather than anything specific to DigitalOcean’s platform.
In the context of your current issue, you can try the following:
secure: true option to ensure they’re only sent over HTTPS. This is especially true if the server is behind a proxy (which is common on most hosting platforms like DigitalOcean). Try updating the cookie object in your session setup:cookie: {
expires: 60000 * 60,
secure: true,
httpOnly: true,
domain: ".section-webapp-y793v.ondigitalocean.app",
sameSite: "none" // You may or may not need this line depending on your use-case.
}
app.set('trust proxy', 1)
express-session, remember that memory stores are not designed for a production environment. They will leak memory under most conditions, do not scale past a single process, and are meant for debugging and developing.For a list of compatible session stores, see the compatible session stores in the express-session readme.
Remember, changes to your session or cookie configuration will typically require a server restart to take effect.
If none of these solutions work, please provide more information or any error messages you’re seeing. I’d be happy to help further.
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.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.