How to secure a web socket connection #2824
-
I am using nextjs 14 with As of now, the web socket connection is not secured, while the regular trpc requests are (in trpc configured with I also know that you can secure I was not able to find a straight forward way to secure the endpoint and the the current user. So, I try to find a way to secure it with Here is my minimal repo with the unsecured web socket connection and clerk setup: https://github.com/NicoVogel/t3-websocket-minimal/tree/feat/clerk Has someone done a more manual approach to setup clerk and may have an idea how to handle this or am I completely on the wrong track? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
If you use // client
const socketInstance = io(apiUrl, {
transports: ["polling", "websocket"], // TODO: check websocket, as it doesn't support additional headers
extraHeaders: {
Authorization: `Bearer ${token}`
}
}); and then: // server
io = new Server(server, {
path: "/socket.io",
transports: ["polling", "websocket"]
});
io.engine.use(ClerkExpressRequireAuth()); |
Beta Was this translation helpful? Give feedback.
-
In case anyone else needs to implement this. |
Beta Was this translation helpful? Give feedback.
In case anyone else needs to implement this.
I created a minimal repo that shows the implementation for the package
ws
.https://github.com/NicoVogel/clerk-secure-websocket