eq-session
v0.1.2
Published
Session module for Eq applications
Downloads
1
Readme
eq-session
Session module for Eq applications. Inspired by ameba/proteus-session
Example
Middleware
const express = require('express'),
session = require('eq-session'),
app = express();
app.use(session.middleware());
Create ticket
const session = require('eq-session'),
id = 'USER_ID';
session.createTicket(id, function (error, ticket) {
if (error) {
next(error);
}
console.log(ticket);
next();
});
Get ID by ticket
const session = require('eq-session'),
ticket = req.get('X-Eq-Session');
session.getId(ticket, function (error, id) {
if (error) {
next(error);
}
console.log(id);
next();
});
Set session data
const session = require('eq-session'),
ticket = req.get('X-Eq-Session');
session.getId(ticket, function (error, id) {
if (error) {
return next(error);
}
const data = {
key: 'value'
};
session.setSession(id, data, function (error) {
if (error) {
next(error);
}
next();
});
});
Get session data
By ID
const session = require('eq-session'),
ticket = req.get('X-Eq-Session');
session.getId(ticket, function (error, id) {
if (error) {
return next(error);
}
session.getSession(id, function (error, result) {
if (error) {
next(error);
}
console.log(result);
next();
});
});
By ticket
const session = require('eq-session'),
ticket = req.get('X-Eq-Session');
session.getTicketSession(ticket, function (error, result) {
if (error) {
return done(error);
}
console.log(result);
next();
});