0

I'm using SailsJS with MongoDB. When users are authenticated, their data is stored in a collection named "Sessions".

I'd like to know how I could access this collection so that I can remove all the data in order to force all users to have to log in again. Possibly using Waterline query.

Thanks

Liquidice
  • 175
  • 1
  • 11
  • read the comments of the `config/sessions.js` as it mentions invalidating your users sessions to force them log in again. – Eli Peters Aug 03 '18 at 13:34

1 Answers1

1

After further investigation, I found a solution.

Create a new Model called Session, with attributes

id: {
    type: 'string',
    unique: true
},

sessions: {
    type: 'json',
    defaultsTo: {}
},

expires: {
    type: 'string',
    defaultsTo: ''
}

After that, you can use Waterline query to edit the session collection, like

Sessions.destroy().exec(function (err, destroyed) {
            if(!err){
                sails.log.info('Session destroyed');
                request.session = '';
                return response.redirect('/');
            }
            else{
                sails.log.error(err);
            }
        });
Liquidice
  • 175
  • 1
  • 11