diff --git a/packages/supabase/src/client/client.ts b/packages/supabase/src/client/client.ts index 8875eb0d8c..ad83bf52ce 100644 --- a/packages/supabase/src/client/client.ts +++ b/packages/supabase/src/client/client.ts @@ -1,8 +1,17 @@ import { createBrowserClient } from "@supabase/ssr"; import type { Database } from "../types"; -export const createClient = () => - createBrowserClient( +export const createClient = () => { + return createBrowserClient( process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, + { + global: { + headers: { + // https://supabase.com/docs/guides/platform/read-replicas#experimental-routing + "sb-lb-routing-mode": "alpha-all-services", + }, + }, + }, ); +}; diff --git a/packages/supabase/src/client/middleware.ts b/packages/supabase/src/client/middleware.ts index 94dc89ec99..a000a34255 100644 --- a/packages/supabase/src/client/middleware.ts +++ b/packages/supabase/src/client/middleware.ts @@ -9,6 +9,12 @@ export async function updateSession( process.env.NEXT_PUBLIC_SUPABASE_URL!, process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY!, { + global: { + headers: { + // https://supabase.com/docs/guides/platform/read-replicas#experimental-routing + "sb-lb-routing-mode": "alpha-all-services", + }, + }, cookies: { get(name: string) { return request.cookies.get(name)?.value; diff --git a/packages/supabase/src/client/server.ts b/packages/supabase/src/client/server.ts index 6e9b8b2e72..9071f6f561 100644 --- a/packages/supabase/src/client/server.ts +++ b/packages/supabase/src/client/server.ts @@ -78,6 +78,8 @@ export const createClient = (options?: CreateClientOptions) => { headers: { // Pass user agent from browser "user-agent": headers().get("user-agent") as string, + // https://supabase.com/docs/guides/platform/read-replicas#experimental-routing + "sb-lb-routing-mode": "alpha-all-services", }, }, },