socketio / socket.io-client-swift

Other
5.21k stars 839 forks source link

Is there a logic in connect(withPayload: ) that automatically wraps dict into auth:dict? #1493

Open kbw2204 opened 3 months ago

kbw2204 commented 3 months ago

I have a question regarding the connect parameter (withPayload) in swift-socketIO. Specifically, I want to know if there is any internal logic that automatically wraps the dictionary into an "auth" key when using withPayload.

I'm trying to set the auth option during connect (like this), but couldn't find any related information in the swift-socketIO documentation.

// Socket.IO doc
const socket = io({
  auth: {
    token: "abc"
  }
});

// swift-socketIO
// ??

then I saw an Github issue where auth information was passed using withPayload, and it worked fine. However, when I wrap the payload with an "auth" key, authentication fails.. Without wrapping it, authentication succeeds.

// authentication ✅
let payload: [String: Any] = [
"token": token
]
manager.connect(withPayload: payload)

// authentication ❌
let payload: [String: Any] = [
    "auth": ["token": token]
]
manager.connect(withPayload: payload)

I checked the internal code of swift-socketIO and couldn't find any logic that automatically wraps the dictionary into an "auth" key. Is there any internal logic in swift-socketIO that does this?

Thank you for your assistance!