elephant.io icon indicating copy to clipboard operation
elephant.io copied to clipboard

Asynchronous authorization

Open sergiopvilar opened this issue 11 years ago • 0 comments

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?

sergiopvilar avatar Feb 03 '15 20:02 sergiopvilar