@@ -4,18 +4,16 @@ import { cookies } from "next/headers";
44/**
55 * Creates a Supabase client for use in Server Components, Route Handlers,
66 * and Server Actions.
7- *
8- * Usage:
9- * import { createClient } from "@/lib/supabase/server";
10- * const supabase = await createClient();
117 */
128export async function createClient ( ) {
13- const supabaseUrl = process . env . NEXT_PUBLIC_SUPABASE_URL ;
14- const supabaseAnonKey = process . env . NEXT_PUBLIC_SUPABASE_ANON_KEY ;
9+ const supabaseUrl =
10+ process . env . NEXT_PUBLIC_SUPABASE_URL || process . env . SUPABASE_URL ;
11+ const supabaseAnonKey =
12+ process . env . NEXT_PUBLIC_SUPABASE_ANON_KEY || process . env . SUPABASE_ANON_KEY ;
1513
1614 if ( ! supabaseUrl || ! supabaseAnonKey ) {
1715 throw new Error (
18- "Missing NEXT_PUBLIC_SUPABASE_URL or NEXT_PUBLIC_SUPABASE_ANON_KEY environment variables" ,
16+ "Missing Supabase environment variables (NEXT_PUBLIC_SUPABASE_URL or SUPABASE_URL) " ,
1917 ) ;
2018 }
2119
@@ -32,9 +30,8 @@ export async function createClient() {
3230 cookieStore . set ( name , value , options ) ;
3331 }
3432 } catch {
35- // The `setAll` method was called from a Server Component.
36- // This can be ignored if you have middleware refreshing
37- // user sessions.
33+ // The setAll method was called from a Server Component.
34+ // This can be ignored if you have proxy refreshing user sessions.
3835 }
3936 } ,
4037 } ,
@@ -44,22 +41,18 @@ export async function createClient() {
4441/**
4542 * Creates a Supabase admin client using the service role key.
4643 * WARNING: This bypasses Row Level Security — use only in trusted server contexts.
47- *
48- * Usage:
49- * import { createAdminClient } from "@/lib/supabase/server";
50- * const supabase = createAdminClient();
5144 */
5245export function createAdminClient ( ) {
53- const supabaseUrl = process . env . NEXT_PUBLIC_SUPABASE_URL ;
46+ const supabaseUrl =
47+ process . env . NEXT_PUBLIC_SUPABASE_URL || process . env . SUPABASE_URL ;
5448 const supabaseServiceRoleKey = process . env . SUPABASE_SERVICE_ROLE_KEY ;
5549
5650 if ( ! supabaseUrl || ! supabaseServiceRoleKey ) {
5751 throw new Error (
58- "Missing NEXT_PUBLIC_SUPABASE_URL or SUPABASE_SERVICE_ROLE_KEY environment variables" ,
52+ "Missing SUPABASE_URL or SUPABASE_SERVICE_ROLE_KEY environment variables" ,
5953 ) ;
6054 }
6155
62- // Import directly to avoid cookie overhead for admin operations
6356 const { createClient } = require ( "@supabase/supabase-js" ) ;
6457 return createClient ( supabaseUrl , supabaseServiceRoleKey , {
6558 auth : {
0 commit comments