import { createServerClient } from "@supabase/ssr"; import { cookies } from "next/headers"; /** * 서버용 Supabase 클라이언트를 생성합니다. * 쿠키 읽기/쓰기 권한이 있어 SSR에 적합합니다. */ 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 { // Server Components에서는 쿠키를 설정할 수 없습니다. // 읽기 전용 에러가 발생합니다. /** * 서버 사이드 인증 상태를 관리하고 보호된 라우트를 처리합니다. */ } }, }, }, ); }