Share your repls and programming experiences

← Back to all posts
Simple socket.io chat with repl.it authentication
TAL0S (5)

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.

Voters
TAL0S (5)
Comments
hotnewtop
ch1ck3n (2358)

a cookie is created with your repl.it id

it's not your replit id

repl.it's "oauth" authentication system.

it's not oauth

TAL0S (5)

@ch1ck3n

it's not oauth

notice how I quoted oauth
I used that because it's oauth-like to a remote degree, meaning that was probably the simplest explanation.

it's not your replit id

Again, relative
id is the simplest way to explain it, even though it is a session-only token

Thanks for commenting