First of all i'm rookie with nodejs, i started to learn it about 3-4 days and i read lots of articles but they made me more confuse!
var app = express();
var expressSession = require('express-session');
var cookieParser = require('cookie-parser');
app.use(cookieParser());
app.use(expressSession({
key : 'session',
secret: 'mySecretKey',
store: sessionStore
}));
app.use(passport.initialize());
app.use(passport.session());
var server= require('http').Server(app) ;
var io = require('socket.io')(server);
var passportSocketIo = require("passport.socketio");
io.use(passportSocketIo.authorize({
cookieParser: cookieParser,
key: 'session',
secret: 'mySecretKey',
store: sessionStore,
success: onAuthorizeSuccess,
fail: onAuthorizeFail,
}));
It works great and check socket connection access, but there's a little big problem for me. How i can access the session id on socket messages? i want to search session data in my session store and find the current users information.
this piece of code seems not working:
io.on('connection',function(socket) {
socket.on('myevent',function(){
console.log("Session: ", socket.session);
});
});
Aucun commentaire:
Enregistrer un commentaire