Tuesday, 14 March 2017

How to clear req.session on clearing browser cookies in node js?

I am using "express": "~4.14.0" with express-session for saving username. Once the user is logged in, I will save the user name in req.session.authorizedUser = username to display it in the application header. If the browsing history is cleared or the broser is closed, I want to empty this session. Please suggest me if there is any way to destroy session when doing any of these two. I have tried with maxAge in session cookies option like the below but doesn't reflects good:

app.use(session({
    secret: "key test",
    resave: false,
    saveUninitialized: true,
    cookie: { secure: !true, path: '/', httpOnly: true, maxAge: null}
}));



via Dhya S

No comments:

Post a Comment