f4e35974c6
Deploy staging to test server / deploy (push) Failing after 14m49s
This reverts commita55c69115d, reversing changes made to02c9c9f3d6.
42 lines
1.5 KiB
TypeScript
42 lines
1.5 KiB
TypeScript
import "server-only";
|
|
|
|
import { createServerClient } from "@supabase/ssr";
|
|
import type { SupabaseClient } from "@supabase/supabase-js";
|
|
import { cookies, headers } from "next/headers";
|
|
import { createLocalPostgresDataClient } from "@/lib/db/local-postgres-client";
|
|
import { readDatabaseUrl } from "@/lib/db/config";
|
|
import { getIdentityAuthServices } from "@/modules/identity/auth";
|
|
import { readIdentitySession } from "@/modules/identity/session";
|
|
import { getSupabasePublicConfig } from "./config";
|
|
|
|
export async function createServerSupabaseClient() {
|
|
if (process.env.AUTH_PROVIDER?.trim() === "self-hosted") {
|
|
const requestHeaders = new Headers(await headers());
|
|
const session = await readIdentitySession(
|
|
getIdentityAuthServices().user.api,
|
|
requestHeaders,
|
|
);
|
|
return createLocalPostgresDataClient(
|
|
readDatabaseUrl(process.env, "APP_DATABASE_URL"),
|
|
session ? { id: session.user.id, email: session.user.email } : null,
|
|
) as unknown as SupabaseClient;
|
|
}
|
|
const { url, anonKey } = getSupabasePublicConfig();
|
|
const cookieStore = await cookies();
|
|
|
|
return createServerClient(url, anonKey, {
|
|
cookies: {
|
|
getAll: () => cookieStore.getAll(),
|
|
setAll: (cookiesToSet) => {
|
|
try {
|
|
cookiesToSet.forEach(({ name, value, options }) => {
|
|
cookieStore.set(name, value, options);
|
|
});
|
|
} catch {
|
|
// Server Components cannot write cookies; Route Handlers can.
|
|
}
|
|
},
|
|
},
|
|
});
|
|
}
|