Phase 1: generate database types and type the Supabase clients
Types are generated from the live database's API schema by scripts/gen-types.mjs (npm run gen:types), in the same shape as supabase gen types, so no Supabase CLI login is needed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import "server-only";
|
||||
|
||||
import { createClient } from "@supabase/supabase-js";
|
||||
|
||||
import type { Database } from "@/lib/database.types";
|
||||
import { serverEnv } from "@/lib/env.server";
|
||||
|
||||
/**
|
||||
@@ -9,7 +10,7 @@ import { serverEnv } from "@/lib/env.server";
|
||||
* AFTER the scoreboard/judge token has been validated, and scope every query by that token.
|
||||
*/
|
||||
export function createAdminClient() {
|
||||
return createClient(serverEnv.NEXT_PUBLIC_SUPABASE_URL, serverEnv.SUPABASE_SERVICE_ROLE_KEY, {
|
||||
return createClient<Database>(serverEnv.NEXT_PUBLIC_SUPABASE_URL, serverEnv.SUPABASE_SERVICE_ROLE_KEY, {
|
||||
auth: { persistSession: false, autoRefreshToken: false },
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { createBrowserClient } from "@supabase/ssr";
|
||||
|
||||
import type { Database } from "@/lib/database.types";
|
||||
import { publicEnv } from "@/lib/env.public";
|
||||
|
||||
/** Anon-key client for the browser: Realtime subscriptions + the admin auth session. */
|
||||
export function createClient() {
|
||||
return createBrowserClient(
|
||||
return createBrowserClient<Database>(
|
||||
publicEnv.NEXT_PUBLIC_SUPABASE_URL,
|
||||
publicEnv.NEXT_PUBLIC_SUPABASE_ANON_KEY,
|
||||
);
|
||||
|
||||
@@ -3,13 +3,14 @@ import "server-only";
|
||||
import { createServerClient } from "@supabase/ssr";
|
||||
import { cookies } from "next/headers";
|
||||
|
||||
import type { Database } from "@/lib/database.types";
|
||||
import { publicEnv } from "@/lib/env.public";
|
||||
|
||||
/** Cookie-based client for admin server components/actions. RLS applies as the signed-in admin. */
|
||||
export async function createClient() {
|
||||
const cookieStore = await cookies();
|
||||
|
||||
return createServerClient(
|
||||
return createServerClient<Database>(
|
||||
publicEnv.NEXT_PUBLIC_SUPABASE_URL,
|
||||
publicEnv.NEXT_PUBLIC_SUPABASE_ANON_KEY,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user