My Sockets work fine when a client has the token (provided by Laravel jwt) but, a need to work with the clients while they aren't authenticated yet, I Want something like:
io.sockets
.on('connection', socketioJwt.authorize({
secret: process.env.JWT_SECRET,
timeout: 15000 // 15 seconds to send the authentication message
}))
.on('authenticated', function(socket) {
console.log('Authenticated!!');
// This works:
socket.on('setDataRegistered', function(datos) {
console.log('Registering!');
});
})
// This doesn't works:
.on('config', function(socket) {
console.log('A client wants to be configured before authenticated!');
})
How can I call from the FrontEnd to 'config' (socket.emit('config')) before authenticate??
Thanks for your help. Sorry my English.
What I do is this:
io.on('connection', function (socket) {
// Client connected but not authenticated. Client has to emit to 'authenticate' for authentication
socket.on('authenticate', function (data, fn) {
// Authenticate socket.
// define more events
});
// still accessible to unauthorised sockets
socket.on("other-event", function(data) {
});
});
I don't use any middleware for authentication. But that's just me. I never found the use for it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With