Liquidice
Liquidice

Reputation: 195

Deleting all data in Sessions store

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

Upvotes: 0

Views: 103

Answers (1)

Liquidice
Liquidice

Reputation: 195

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);
            }
        });

Upvotes: 1

Related Questions