Tuesday, 6 June 2017

How can I clear express session for all users without restarting the application ?

I am developing REST services using nodejs express framework and keeping the user specific data in the session with user's id as key to identify user's data.

Here Is the code I am using to store user specific data:

let session = require("express-session");
let FileStore = require("session-file-store")(session);

//For setting up the data into session
session[userId]={name:xyz, age:22}

//For getting the data
session[userId]

I have also configured session with expiry time, which must clear out all the session value.

  webserver.use(session({
        cookie: {
            maxAge: 60 * 1000 // 24 hours
            // maxAge: 24 * 60 * 60 * 1000 // 24 hours
        },
        key: "sid",
        resave: false,
        saveUninitialized: false,
        secret: "keyboard cat",
        store: new FileStore(storageOptions),
    }));`

but the session values seems persisted even after expiry time exceeded. although these are rest service and no cookies are involved in this, I am using user's id instead.

As per my understanding this session should be clear out after expiry time exceeded but it's not.

Question 1 : How can I clear complete session values anytime without restarting the server ? Question 2 : Why expiry time is not working as per above code ?

I am doing something wrong ?

Please help

Thanks in advance



via Deepak

No comments:

Post a Comment