简体   繁体   English

如何使用socketio-jwt发出和接收whitout a Authenticated

[英]How to emit and recieve whitout a Authenticated using socketio-jwt

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: 当客户端拥有令牌(由Laravel jwt提供)时,我的套接字工作正常,但是,当他们尚未经过身份验证时需要与客户端合作,我想要类似于:

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?? 如何在进行身份验证之前从FrontEnd调用'config'(socket.emit('config'))?

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. 我从来没有找到它的用途。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM