feat: block access for pin protected rooms

This commit is contained in:
Mat12143 2025-08-02 13:00:11 +02:00
parent 7587796934
commit 1063c239b6
3 changed files with 5 additions and 4 deletions

View file

@ -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" import { parseSong, parseSuggestion, type FetchError, type Song, type Suggestion } from "./types"
export const joinRoom = async function (roomId: string, coords: Coordinates): Promise<[FetchError | null, string]> { 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}`) let res = await fetch(`/api/join?room=${roomId}&lat=${coords.latitude}&lon=${coords.longitude}&pin=${pin}`)
if (res.status != 200) { if (res.status != 200) {
return [{ code: 400, message: "Cannot join the room" }, ""] return [{ code: 400, message: "Cannot join the room" }, ""]

View file

@ -31,7 +31,7 @@
} }
let sugg, queue, index let sugg, queue, index
;[returnError] = await joinRoom(data.roomId, coords) ;[returnError] = await joinRoom(data.roomId, coords, data.pin)
if (returnError) { if (returnError) {
return return
} }

View file

@ -3,5 +3,6 @@ import type { PageLoad } from "./$types"
export const load: PageLoad = ({ params, url }) => { export const load: PageLoad = ({ params, url }) => {
return { return {
roomId: params.id || "", roomId: params.id || "",
pin: url.searchParams.get("pin") || "",
} }
} }