Trying to view all logged in Users in Express.js Node.js Passport.js

后端 未结 1 1756
耶瑟儿~
耶瑟儿~ 2020-12-21 23:08

Trying to see all sessions of all logged in users in Express Passport, and want be able to see who is currently logged in. Whats the best and quickest means?

I was t

相关标签:
1条回答
  • 2020-12-22 00:07

    In the case of using express-session (if store is default value: MemoryStore) you can get store object and sessions array from req object:

    var sessions = req.sessionStore.sessions
    

    For example (for me) it looks like that:

    {
        KT29eOp9XkzFfXWdz_UVUQMI4Qf3VTxE: 
            '{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},
            "passport":{"user":"5a95b34b52670e19200ec48e"}}',
        WW7BAhNNBbuFUsKQ0dbalgToEEfGES8p: 
            '{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},
            "passport":{"user":"5a9d56a18149111cf0556991"}}' 
    }             
    

    user values in passport props are _id of your users in MongoDB User collection.

    0 讨论(0)
提交回复
热议问题