“Socket.io Authentication” Kode Jawaban

Socket.io Authentication

req.session.regenerate...
res.send({rediskey: req.sessionID});
SAMER SAEID

Socket.io Authentication

//in io.on('connection')
io.on('connection', function(client) {
  client.on('message', function(message) {

    if(message.rediskey) {
      //fetch session info from redis
      redisclient.get(message.rediskey, function(e, c) {
        client.user_logged_in = c.username;
      });
    }

  });
});
SAMER SAEID

Socket.io Authentication

//store the key in a cookie
SetCookie('rediskey', <%= rediskey %>); //http://msdn.microsoft.com/en-us/library/ms533693(v=vs.85).aspx

//then when socket is connected, fetch the rediskey from the document.cookie and send it back to server
var socket = new io.Socket();

socket.on('connect', function() {
  var rediskey = GetCookie('rediskey'); //http://msdn.microsoft.com/en-us/library/ms533693(v=vs.85).aspx
  socket.send({rediskey: rediskey});
});
SAMER SAEID

Jawaban yang mirip dengan “Socket.io Authentication”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya