mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-16 02:35:37 +02:00
⭐feat: Add a websocket party (#152)
This adds functionality to connect to remote server thru the party
This commit is contained in:
21
packages/functions/src/party/utils.ts
Normal file
21
packages/functions/src/party/utils.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import type * as Party from "partykit/server";
|
||||
|
||||
export async function tryAuthentication(req: Party.Request, lobby: Party.Lobby) {
|
||||
const authHeader = req.headers.get("authorization") ?? new URL(req.url).searchParams.get("authorization")
|
||||
if (authHeader) {
|
||||
const match = authHeader.match(/^Bearer (.+)$/);
|
||||
|
||||
if (!match || !match[1]) {
|
||||
throw new Error("Bearer token not found or improperly formatted");
|
||||
}
|
||||
|
||||
const bearerToken = match[1];
|
||||
|
||||
if (bearerToken !== lobby.env.AUTH_FINGERPRINT) {
|
||||
throw new Error("Invalid authorization token");
|
||||
}
|
||||
|
||||
return req// app.fetch(req as any, { room: this.room })
|
||||
}
|
||||
throw new Error("You are not authorized to be here")
|
||||
}
|
||||
Reference in New Issue
Block a user