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

export async function load({fetch}){
    const res = await fetch(`${PUBLIC_API_URL}/game`, {
        method: "GET",
        headers: {"Content-Type": "application/json"},
        credentials: "include"
    });

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

    return {data};
}
