Supabase-Clients (Browser/Server/Admin), Session-Proxy und Basis-Typen

This commit is contained in:
2026-07-17 18:18:19 +02:00
parent 63a30a3835
commit 74ce663813
8 changed files with 360 additions and 2 deletions
+14
View File
@@ -0,0 +1,14 @@
import "server-only";
import { createClient as createSupabaseClient } from "@supabase/supabase-js";
// Service-Role-Client: umgeht RLS. Ausschließlich serverseitig verwenden
// (Benutzerverwaltung durch den Admin).
export function createAdminClient() {
return createSupabaseClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.SUPABASE_SERVICE_ROLE_KEY!,
{
auth: { persistSession: false, autoRefreshToken: false },
}
);
}
+15
View File
@@ -0,0 +1,15 @@
import { createBrowserClient } from "@supabase/ssr";
// Browser-Client (Client Components). Passkey-Support ist bei Supabase
// derzeit als experimentelles Feature markiert und muss aktiviert werden.
export function createClient() {
return createBrowserClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
auth: {
experimental: { passkey: true },
},
}
);
}
+30
View File
@@ -0,0 +1,30 @@
import { createServerClient } from "@supabase/ssr";
import { cookies } from "next/headers";
// Server-Client (Server Components, Route Handler, Server Actions).
// Muss pro Request neu erzeugt werden.
export async function createClient() {
const cookieStore = await cookies();
return createServerClient(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!,
{
cookies: {
getAll() {
return cookieStore.getAll();
},
setAll(cookiesToSet) {
try {
cookiesToSet.forEach(({ name, value, options }) =>
cookieStore.set(name, value, options)
);
} catch {
// In Server Components dürfen keine Cookies gesetzt werden –
// das Session-Refresh übernimmt proxy.ts.
}
},
},
}
);
}