I
I
Ilya Beloborodov2016-05-03 01:58:24
Node.js
Ilya Beloborodov, 2016-05-03 01:58:24

Why is the modified handshake not being sent?

io.set('authorization', function (handshake, accept) {
   ///.......
   handshake.user='some string';
   accept(null, true);

});

below
io.on('connection', function(socket){
        console.log('a user connected');
        console.log(socket.handshake.user);
        // .......
});

In the console I see
a user connected
undefined

But why undefined if it should be some string?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Litvinenko, 2016-05-03
@edli007

I don’t remember exactly, but it seems I did it through io.use and not io.set

I
Ilya Beloborodov, 2016-05-03
@kowap

Hooray. You need to knock on the object like this

io.on('connection', function(socket){
        console.log('a user connected');
        console.log(socket.request.user);
        // .......
});

www.stackoverflow.com

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question