facundoolano / socketio-auth

Authentication module for socket.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

postAutheticate() question

AlexisNi opened this issue · comments

I want to send the userId from the client to server,so after the user is athenticated ,from then clinet side i want to emit the userId to the server .I would like to ask if there is a the right way of using postAuthentcate?I used like this
require('socketio-auth')(io, {
authenticate: function (socket, data, callback) {

    if (data.password=='123'){
        console.log('authenticated');
        return callback(null, true);
    }else{
        return callback(new Error('Wrong Password'));
    }
},
postAuthenticate:function(socket, data) {
    socket.on('get-userId',function (userId) {
        console.log('Welcome user : '+userId.userId);

    });
}

});

From your code and description it would sound as if you should just need to send userId + password when you emit authentication on the client, without the need to use postAuthenticate