import {PUBLIC_API_URL} from "$env/static/public";
import {error} from "@sveltejs/kit";

export async function load({fetch, params}){
    const {game_id} = params;

    const response = await fetch(`${PUBLIC_API_URL}/game/${game_id}`, {
        method: "GET",
        headers: {"Content-Type": "application/json"},
        credentials: "include"
    });

    const data = await response.json();
    if(!response.ok){
        if(response.status === 401){
            error(response.status, {
                message: data.error.message,
                back: "/"
            })
        }
    }

    return {data};
}
