kartikk221/hyper-express-session

Touch event with memcached

Closed this issue · 1 comments

I store sessions in memcached with this code

const SessionEngine = require('hyper-express-session');
const Memcached = require('memcached');
const memcached = new Memcached('memcached:11211');

const TOKEN_EXPIRE = 60 * 45; // Default duration is 45 Minutes

const sessionEngine = new SessionEngine({
    duration: 1000 * TOKEN_EXPIRE,
    cookie: {
        name: 'my_session',
        path: '/',
        httpOnly: true,
        secure: true,
        sameSite: 'strict',
        secret: '-------------------'
    }
});

const getMemcached = key => new Promise((resolve, reject) => memcached.get(key, (err, data) => {
    if(err) reject(); else resolve(data);
}));

sessionEngine.use('read', async session => await getMemcached(session.id));
sessionEngine.use('touch', session => memcached.touch(session.id, ?????????????, err => console.error(err)));
sessionEngine.use('write', session => memcached.set(session.id, session.get(), TOKEN_EXPIRE, err => console.error(err)));
sessionEngine.use('destroy', session => memcached.del(session.id, err => console.error(err)));

module.exports = sessionEngine

What value for the "expiry timestamp" is icorrect to use with "touch" event?

P.S. Memcached time is in seconds

Hello,
You can read the session.expires_at property and then divide it by 1000 to get the UNIX timestamp in seconds at which the session should expire.