mirror of
https://github.com/nestriness/nestri.git
synced 2025-12-13 01:05:37 +02:00
21 lines
741 B
TypeScript
21 lines
741 B
TypeScript
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")
|
|
} |