Question

Deployed express server isn't creating a session?

Posted July 26, 2021 201 views
MySQLNode.jsDigitalOceanJavaScript

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 })
    }
}
)
Submit an answer

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!