node.js - Express and Redis - If session exists for this user, don't allow access -
i using redis , express this:
// app.js var redis = require('redis'), redisclient = redis.createclient(), session = require('express-session'), redisstore = require('connect-redis')(session); session = session({ store: new redisstore({client: redisclient}), secret: 'secretkey', resave: true, saveuninitialized: true }) app.use(session);
in index route file, set user session this:
req.session.user = user; when user comes (or opens tab), how detect how many sessions having , block him access if has 1 active session?
express-session working via cookies. had cookie named session sessionid. tabs inside browsed share cookies , can't rely on cookies if want strict working via 1 browser tab.
you need create own sessions each opened browser tab. generating tabid @ client side , saving {userid, tabid} redis
or can use websockets (http://socket.io/) that, little overhead, doing want
Comments
Post a Comment