Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumerating all sessions #92

Open
AHarmlessPyro opened this issue Sep 11, 2020 · 1 comment
Open

Enumerating all sessions #92

AHarmlessPyro opened this issue Sep 11, 2020 · 1 comment

Comments

@AHarmlessPyro
Copy link

AHarmlessPyro commented Sep 11, 2020

I've tried to look for a method to enumerate the sessions present on express using session-file-store. Seemingly there is a list method to do that. I've tried to access it like request.sessionStore.list() (Edit : which gives me a null value) and FileStore.prototype.list (with FileStore being a const holding the reference to the session-file-store object). The first doesn't work at all and the second raises a problem with the path attribute of options var (used inside helpers.list) being undefined. The general usage seems to be . If there is a better way to do this, It'd be greatly appreciated.

This is my code :
app.get('/scores', cors(), (req, res) => { console.log(req.session) console.log(req.sessionStore.list((callbackVar) => { console.log(callbackVar) })) let sess_count = 0 console.log(FileStore.prototype.list(function session_count(a, len) { sess_count = len; console.log("Total active session count is " + sess_count); console.log("============"); }) ) }
<Code is not complete, only relevant sample is being passed>

image

Error produced when doing FileStore.prototype..list is :
App starting index.js:226 Session {cookie: Cookie, name: '<something>', quizTimeObj: {…}, t1_score: {…}, t2_score: {…}} index.js:195 undefined index.js:196 null index.js:197 TypeError: Cannot read property 'path' of undefined at Object.list (c:\Users\<something>\Google Drive\projects\Quizzer\node_modules\session-file-store\lib\session-file-helpers.js:352:24) at Store.FileStore.list (c:\Users\<something>\Google Drive\projects\Quizzer\node_modules\session-file-store\lib\session-file-store.js:120:13) at c:\Users\<something>\Google Drive\projects\Quizzer\index.js:200:37 at Layer.handle [as handle_request] (c:\Users\<something>\Google Drive\projects\Quizzer\node_modules\express\lib\router\layer.js:95:5) at next (c:\Users\<something>\Google Drive\projects\Quizzer\node_modules\express\lib\router\route.js:137:13) at cors (c:\Users\<something>\Google Drive\projects\Quizzer\node_modules\cors\lib\index.js:188:7)
image

@AHarmlessPyro
Copy link
Author

Seems like my approach was flawed. The list method seems to function reasonably close to all() method from express-session. Using the get() method on the store then gives me the results. One thing that I noted was that the sessionID(s) all had a .json extension. Seemingly the get method then added a .json at the end and as a result it was .json.json which couldn't be found.

let sessStore = req.sessionStore;
    let data = req.sessionStore.list((a, b) => {
        if (a) {
            console.error(a)
        } else {
            console.log(b)
            console.log(sessStore)
            let trueVal = b.map((cookieID) => {
                console.log(cookieID.split('.')[0])
                sessStore.get(cookieID.split('.')[0], (err, sess) => {
                    if (err) {
                        console.log(err)
                    } else {
                        console.log(sess)
                        return 0;
                    }
                })

So the sample code that I am using right now strips the .json at the end before passing it to the get() method.
image

I'll wait a bit for the dev response before closing the issue to make sure that I'm not doing something wrong here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant