From 1063c239b6c0aa9e22d99a749704ebe645af94c0 Mon Sep 17 00:00:00 2001 From: Mat12143 Date: Sat, 2 Aug 2025 13:00:11 +0200 Subject: [PATCH] feat: block access for pin protected rooms --- frontend/src/lib/utils.ts | 6 +++--- frontend/src/routes/room/[id]/+page.svelte | 2 +- frontend/src/routes/room/[id]/+page.ts | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts index 6450247..470da85 100644 --- a/frontend/src/lib/utils.ts +++ b/frontend/src/lib/utils.ts @@ -1,8 +1,8 @@ -import { get_coords, type Coordinates } from "./gps" +import { type Coordinates } from "./gps" import { parseSong, parseSuggestion, type FetchError, type Song, type Suggestion } from "./types" -export const joinRoom = async function (roomId: string, coords: Coordinates): Promise<[FetchError | null, string]> { - let res = await fetch(`/api/join?room=${roomId}&lat=${coords.latitude}&lon=${coords.longitude}`) +export const joinRoom = async function (roomId: string, coords: Coordinates, pin: string): Promise<[FetchError | null, string]> { + let res = await fetch(`/api/join?room=${roomId}&lat=${coords.latitude}&lon=${coords.longitude}&pin=${pin}`) if (res.status != 200) { return [{ code: 400, message: "Cannot join the room" }, ""] diff --git a/frontend/src/routes/room/[id]/+page.svelte b/frontend/src/routes/room/[id]/+page.svelte index 76984f3..84d8d67 100644 --- a/frontend/src/routes/room/[id]/+page.svelte +++ b/frontend/src/routes/room/[id]/+page.svelte @@ -31,7 +31,7 @@ } let sugg, queue, index - ;[returnError] = await joinRoom(data.roomId, coords) + ;[returnError] = await joinRoom(data.roomId, coords, data.pin) if (returnError) { return } diff --git a/frontend/src/routes/room/[id]/+page.ts b/frontend/src/routes/room/[id]/+page.ts index 1f9f77d..f3bea98 100644 --- a/frontend/src/routes/room/[id]/+page.ts +++ b/frontend/src/routes/room/[id]/+page.ts @@ -3,5 +3,6 @@ import type { PageLoad } from "./$types" export const load: PageLoad = ({ params, url }) => { return { roomId: params.id || "", + pin: url.searchParams.get("pin") || "", } }