Hi,
I want to use a custom Websocket Server (using Bun) for my application. However I cant really figure out authentication on custom servers. Session cookies seem to be HTTP and secure only, which prevents me from reading them in localhost.
How would I implement the authentication here?
Bun.serve({
port: parseInt(process.env.PORT as string),
hostname: "localhost",
development: true,
async fetch(req, server) {
// ... authenticate here
if (server.upgrade(req)) {
return undefined;
}
return new Response("Upgrade failed", { status: 500 });
},
websocket: {
// ...
},
});
the way discord handle websocket is that :
- the user connects to the websocket
- then sends a message with the auth infos (e.g. the discord token)
- if the server receive the auth infos, it checks it and start the handle for the messages
- if the user does not send the auth message in 60s, the server disconnect the user
follow the same flow for SSR login: https://appwrite.io/docs/products/auth/server-side-rendering.
Make sure you use a custom endpoint that matches your backend endpoint.
Then, the appwrite cookie will be sent to both appwrite and your backend and can be used for auth
Recommended threads
- hi guys! my site is not accesible in my ...
- MongoDb Database Breaks integer[] & bigi...
I've got a table with the below column created. When I try to insert the value `[-3408048000]` into it, the dart sdk cloud function call is successful (no error...
- Error can not create `tablesdb` event wi...
When i'm trying to add an event with `tablesdb` i get an error message My event value: `tablesdb.mtg-decklist-dev.tables.queue_parsing.rows.*.create` Same err...