Apologies, I should have been more clear

Apologies, I should have been more clear. I have a scenario where a user establishes a WebSocket connection first, and then I need to authenticate that user. The flow I am considering is as follows: The client establishes a WebSocket connection with the server. After the connection is established, the client sends an authentication message containing the authentication token. The server verifies the token. Upon successful verification, the server associates the specific WebSocket connection with the user ID extracted from the token. [I need guidance on this part] Here’s how I am currently handling this: When accepting the connection, I tag the connection with a UUID. Upon authentication, I update the KV store with the UUID and the user associated with it. I use getTags to fetch the user ID information. I want to make sure I am correctly associating the WebSocket connection with the user ID for subsequent operations. Is there anything you would recommend changing or improving in this approach? Thanks in advance for your help!
3 Replies
Milan
Milan6mo ago
Does the auth need to outlast the websocket connection? You might be able to use serializeAttachment(), which should live as long as the websocket connection instead of writing it to persistent storage. Might not be great if you don't want to reauthenticate upon client reconnect (if the connection fails for some reason)
Ashrith
AshrithOP6mo ago
Thanks @milan that is something i missed in the docs, reconnect is something that is needed, any recommended ways to handle this?
Milan
Milan6mo ago
It depends on how often you're trying to get(UUID) now. FWIW when you write to storage / read a value back, it gets cached so subsequent reads are fast anyways. If you find the latency is too high, you can try to directly cache in DOs memory + store via serializeAttachment()
Want results from more Discord servers?
Add your server