Replies: 1 comment
|
io.use((socket, next) => { if (key !== "super-secret-123") { socket.isAuthorized = true; |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
This project uses a simple key-based authentication mechanism for Socket.IO to demonstrate how real-time authentication works.
How it works:
The backend generates a unique key when a user logs in.
The key is stored in memory (Map) on the server.
The client sends this key during the Socket.IO connection (handshake.auth).
The server validates the key in a Socket.IO middleware.
Only clients with a valid key are allowed to establish a socket connection.
In production, this logic should be replaced with JWT or a persistent session store (e.g., Redis).
All reactions