tRPCttRPC
Powered by
TOBIIT
tRPCβ€’2y agoβ€’
1 reply
TOBII

WebSocket Authentication: Cookie missing

Hi community πŸ‘‹

I'm currently trying to integrate the wsLink, and I've noticed that cookies are not automatically sent during initialization (first request).
What could be the reason for this? My website runs under the URL http://localhost:3000, and the web server under http://localhost:3001. Does it have something to do with CORS?

Example HTTP-Headers:
...
Cookie: __session=364fc095-9f34-4800-a074-18f0ff4a4876;...
...
...
Cookie: __session=364fc095-9f34-4800-a074-18f0ff4a4876;...
...


Example WebSocket-Headers:
GET ws://localhost:3001/ HTTP/1.1
Host: localhost:3001
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Upgrade: websocket
Origin: http://localhost:3000
Sec-WebSocket-Version: 13
Accept-Encoding: gzip, deflate, br, zstd
Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7
Sec-WebSocket-Key: vC+ByJ+m9oD6Q/r2Rg89Og==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits
GET ws://localhost:3001/ HTTP/1.1
Host: localhost:3001
Connection: Upgrade
Pragma: no-cache
Cache-Control: no-cache
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Upgrade: websocket
Origin: http://localhost:3000
Sec-WebSocket-Version: 13
Accept-Encoding: gzip, deflate, br, zstd
Accept-Language: de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7
Sec-WebSocket-Key: vC+ByJ+m9oD6Q/r2Rg89Og==
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits


I created the WebSocket client as follows:
splitLink({
  condition: (op) => op.type === "subscription",
  true: wsLink({
    transformer: SuperJSON,
    client: createWSClient({
      url: "ws://localhost:3001",
      // lazy: { enabled: true, closeMs: 10000 },
    }),
  }),
  false: createHttpBatchStreamLink(),
})
splitLink({
  condition: (op) => op.type === "subscription",
  true: wsLink({
    transformer: SuperJSON,
    client: createWSClient({
      url: "ws://localhost:3001",
      // lazy: { enabled: true, closeMs: 10000 },
    }),
  }),
  false: createHttpBatchStreamLink(),
})


Server Environment:
Tested with Bun v1.0.29 and Node v20.10.0
Tested with Bun v1.0.29 and Node v20.10.0


Client Environment:
"@trpc/client": "next",
"@trpc/next": "next",
"@trpc/react-query": "next",
"@trpc/server": "next",
"@trpc/client": "next",
"@trpc/next": "next",
"@trpc/react-query": "next",
"@trpc/server": "next",


Thank you in advance. Regards, Tobi
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Cookie authentication flow
sevenSseven / ❓-help
2y ago
websocket testing
ObiOObi / ❓-help
2y ago