elephant.io
elephant.io copied to clipboard
Asynchronous authorization
Hey guys, recently I had a problem with a asynchronous authorization.
Something like that:
io.use(function(socket, next){
var handshakeData = socket.request;
if (!handshakeData)
return next(new Error('[[error:not-authorized]]'));
// The problem is this async request
request(MYURL, function(error, response, body){
try{
if(error) throw new Error(error);
var obj = JSON.parse(body);
if(obj.status){
logger.info('Handshake authorized');
next();
}else{
throw new Error('Invalid API KEY');
}
}catch(e){
logger.info('Handshake denied');
return next(e);
}
});
});
With a asyncrhonous authorization aparentlly Elephant.io disconnects before send the Emit message. I think that would be a good idea warn in the documentation about this problem, what do you think?