Harden gameplay timing and map loading

This commit is contained in:
2026-10-05 15:15:35 +05:00
parent 8b31891776
commit dcc3779262
36 changed files with 1050 additions and 205 deletions

View File

@@ -4,11 +4,12 @@ import { createServerClient } from "@supabase/ssr";
import { cookies } from "next/headers";
import { cache } from "react";
import type { Database } from "@/shared/database";
import { ServiceError, checkServiceError } from "./service-error";
let singleton: ReturnType<typeof createClient<Database>> | undefined;
export function admin() {
if (!process.env.NEXT_PUBLIC_SUPABASE_URL || !process.env.SUPABASE_SECRET_KEY)
throw new Error(
"Supabase configuration missing. Run npm run setup and configure .env.local.",
throw new ServiceError(
"MineGeo is not configured yet. Please try again later.",
);
return (singleton ??= createClient<Database>(
process.env.NEXT_PUBLIC_SUPABASE_URL,
@@ -51,9 +52,9 @@ export const user = cache(async function user() {
});
export function required<T>(result: {
data: T;
error: { message: string } | null;
error: { message: string; code?: string } | null;
}): NonNullable<T> {
if (result.error) throw new Error(result.error.message);
checkServiceError(result.error);
if (result.data === null || result.data === undefined)
throw new Error("Record not found");
return result.data as NonNullable<T>;