Simple socket.io chat with repl.it authentication
On a whim I made a relatively simple socket.io chat - except using repl.it's "oauth" authentication system.
How it works
Socket.io
Client sends messages to server, which relays them, along with the username of the sender, to the other clients. Server joins and leaves are also announced.
Repl.it auth
The server checks for the "x-replit-user-name" header when you request the file. By default this header doesn't exist, meaning that you will appear as a "Guest".
When you click the login button, it creates a repl.it login popup. When this is completed, a cookie is created with your repl.it id, as well as the "x-replit-user-name" HTTP header.
The client then reloads. Now the server checks for the username header again, and finds it! it will now use this username inside the chat as your nickname.
it's not your replit id
it's not oauth
@ch1ck3n
notice how I quoted oauth
I used that because it's oauth-like to a remote degree, meaning that was probably the simplest explanation.
Again, relative
id is the simplest way to explain it, even though it is a session-only token
Thanks for commenting