Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-socket.io-session

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-socket.io-session - npm Package Compare versions

Comparing version 1.3.4 to 1.3.5

.eslintrc.json

60

example/index.js

@@ -1,11 +0,11 @@

var debug = require("debug")("express-socket.io-session:example"),
app = require("express")(),
server = require("http").createServer(app),
io = require("socket.io")(server),
session = require("express-session")({
secret: "my-secret",
var debug = require('debug')('express-socket.io-session:example'),
app = require('express')(),
server = require('http').createServer(app),
io = require('socket.io')(server),
session = require('express-session')({
secret: 'my-secret',
resave: true,
saveUninitialized: true
}),
sharedsession = require("../");
sharedsession = require('../');

@@ -23,4 +23,4 @@ // Attach session

//Debugging express
app.use("*", function(req, res, next) {
debug("Express `req.session` data is %j.", req.session);
app.use('*', function(req, res, next) {
debug('Express `req.session` data is %j.', req.session);
next();

@@ -30,49 +30,49 @@ });

io.use(function(socket, next) {
debug("socket.handshake session data is %j.", socket.handshake.session);
debug('socket.handshake session data is %j.', socket.handshake.session);
next();
});
app.use(require("express").static(__dirname));
app.use(require('express').static(__dirname));
// Set session data via express request
app.use("/login", function(req, res, next) {
debug("Requested /login");
app.use('/login', function(req, res, next) {
debug('Requested /login');
req.session.user = {
username: "OSK"
username: 'OSK'
};
//req.session.save();
res.redirect("/");
res.redirect('/');
});
// Unset session data via express request
app.use("/logout", function(req, res, next) {
debug("Requested /logout");
app.use('/logout', function(req, res, next) {
debug('Requested /logout');
delete req.session.user;
//req.session.save();
res.redirect("/");
res.redirect('/');
});
io.on("connection", function(socket) {
socket.emit("sessiondata", socket.handshake.session);
io.on('connection', function(socket) {
socket.emit('sessiondata', socket.handshake.session);
// Set session data via socket
debug("Emitting session data");
socket.on("login", function() {
debug("Received login message");
debug('Emitting session data');
socket.on('login', function() {
debug('Received login message');
socket.handshake.session.user = {
username: "OSK"
username: 'OSK'
};
debug("socket.handshake session data is %j.", socket.handshake.session);
debug('socket.handshake session data is %j.', socket.handshake.session);
// socket.handshake.session.save();
//emit logged_in for debugging purposes of this example
socket.emit("logged_in", socket.handshake.session);
socket.emit('logged_in', socket.handshake.session);
});
// Unset session data via socket
socket.on("logout", function() {
debug("Received logout message");
socket.on('logout', function() {
debug('Received logout message');
socket.handshake.session.user = {};
// socket.handshake.session.save();
//emit logged_out for debugging purposes of this example
debug("socket.handshake session data is %j.", socket.handshake.session);
debug('socket.handshake session data is %j.', socket.handshake.session);
socket.emit("logged_out", socket.handshake.session);
socket.emit('logged_out', socket.handshake.session);
});

@@ -79,0 +79,0 @@ });

@@ -1,4 +0,4 @@

var cookieparser = require("cookie-parser");
var debug = require("debug")("express-socket.io-session");
var crc = require("crc").crc32;
var cookieparser = require('cookie-parser');
var debug = require('debug')('express-socket.io-session');
var hash = require('./lib/hash');
// The express session object will be set

@@ -24,3 +24,3 @@ // in socket.handskake.session.

// Accept options as second argument if only 2 parameters passed
if (arguments.length == 2 && typeof cookieParserMiddleware === "object") {
if (arguments.length == 2 && typeof cookieParserMiddleware === 'object') {
options = cookieParserMiddleware;

@@ -30,6 +30,6 @@ cookieParserMiddleware = undefined;

if (typeof cookieParserMiddleware === "undefined") {
if (typeof cookieParserMiddleware === 'undefined') {
debug(
"No cookie-parser instance passed as argument. Creating a cookie-parser " +
"instance with default values"
'No cookie-parser instance passed as argument. Creating a cookie-parser ' +
'instance with default values'
);

@@ -40,3 +40,3 @@ cookieParserMiddleware = cookieparser();

var saveUninitializedSession = options.saveUninitialized;
debug("Creating socket.io middleware");
debug('Creating socket.io middleware');

@@ -57,7 +57,7 @@ socketIoSharedSessionMiddleware = function(socket, next) {

debug(
"Using autoSave feature. express-session middleware will be called on every event received"
'Using autoSave feature. express-session middleware will be called on every event received'
);
socket.onevent = function() {
debug(
"Executing socket.onevent monkeypatched by express-socket.io-session"
'Executing socket.onevent monkeypatched by express-socket.io-session'
);

@@ -69,7 +69,8 @@ var _args = arguments;

_onevent.apply(socket, _args);
process.nextTick( function() {
process.nextTick(function() {
if (shouldSave(req)) {
req.session.touch();
req.session.save();
}
} );
});
};

@@ -80,3 +81,3 @@ }

if (err) {
debug("cookieParser errored");
debug('cookieParser errored');
return next(err);

@@ -94,20 +95,2 @@ }

/**
* Hash the given `sess` object omitting changes to `.cookie`.
*
* @param {Object} sess
* @return {String}
* @private
*/
function hash(sess) {
return crc(
JSON.stringify(sess, function(key, val) {
if (key !== "cookie") {
return val;
}
})
);
}
// check if session has been modified

@@ -126,5 +109,5 @@ function isModified(sess) {

// cannot set cookie without a session ID
if (typeof req.sessionID !== "string") {
if (typeof req.sessionID !== 'string') {
debug(
"session ignored because of bogus req.sessionID %o",
'session ignored because of bogus req.sessionID %o',
req.sessionID

@@ -131,0 +114,0 @@ );

{
"name": "express-socket.io-session",
"version": "1.3.4",
"version": "1.3.5",
"description": "Share a cookie-based express-session middleware with socket.io",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"lint": "eslint .",
"prettier": "prettier",
"test": "jest",
"changelog": "git changelog -n changelog.md"
},

@@ -29,4 +32,8 @@ "repository": {

"devDependencies": {
"prettier": "^1.13.5"
"eslint": "^5.0.1",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-prettier": "^2.6.2",
"jest": "^23.3.0",
"prettier": "1.13.7"
}
}

@@ -147,3 +147,7 @@ express-socket.io-session

## Changelog
See [changelog.md](changelog.md)
## License

@@ -150,0 +154,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc