You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd like to have the ability to check for certain cookies before allowing a WebSocket connection, as well as have access to the Elysia context. Here's some demo code:
import{Elysia,ws}from'elysia'importcookiefrom'@elysiajs/cookie';newElysia().use(cookie()).use(ws()).state('count',0).ws('/ws',{beforeHandle({ cookie, store }){if(!cookie['authToken'])returnnewResponse(null,{status: 401});console.log(store.count);}}).listen(8080)
When I run tsc, I get these errors for cookie in the params and store.count:
index.ts:9:18 - error TS2339: Property 'cookie' does not exist on type '{ request: Request; headers: Record<string, string | null>; query: Record<string, unknown>; params: Record<never, string>; body: unknown; store: {}; set: { headers: Record<...>; status?: number | undefined; redirect?: string | undefined; }; } & Record<...>'.
9 beforeHandle({ cookie, store }) {
~~~~~~
index.ts:12:22 - error TS2339: Property 'count' does not exist on type '{}'.
12 console.log(store.count);
~~~~~
Found 2 errors in the same file, starting at: index.ts:9
Ideally, I should be able to access anything available on the context in these WebSocket handlers as I would in regular HTTP endpoints.
I'm currently using Bun 0.6.8, and bun pm ls outputs
EDIT: This might not be relevant for right now, but I'd like to see the notion of a derive in the context of WebSockets, e.g. some way to add data to the "ws" objects passed into open / message / close. This'd be real handy if I wanted to attach certain data, such as user IDs.
The text was updated successfully, but these errors were encountered:
hesxenon
added a commit
to hesxenon/elysia
that referenced
this issue
Aug 22, 2023
@bigbeno37 can you check if the derivations you'd like to see aren't already added by e.g. logging ws.data? Since other derivations are indeed added (but haven't been exposed by the types) I think your request has already been fulfilled?
I'd like to have the ability to check for certain cookies before allowing a WebSocket connection, as well as have access to the Elysia context. Here's some demo code:
When I run
tsc
, I get these errors forcookie
in the params andstore.count
:Ideally, I should be able to access anything available on the context in these WebSocket handlers as I would in regular HTTP endpoints.
I'm currently using Bun
0.6.8
, andbun pm ls
outputsEDIT: This might not be relevant for right now, but I'd like to see the notion of a derive in the context of WebSockets, e.g. some way to add data to the "ws" objects passed into open / message / close. This'd be real handy if I wanted to attach certain data, such as user IDs.
The text was updated successfully, but these errors were encountered: