Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Nov 23, 2024
1 parent 7dad9e8 commit 796e94a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
59 changes: 30 additions & 29 deletions packages/supabase/src/client/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ console.log = (...args) => {
type CreateClientOptions = {
admin?: boolean;
schema?: "public" | "storage";
balancer?: boolean;
};

export const createClient = (options?: CreateClientOptions) => {
const { admin = false, ...rest } = options ?? {};
const { admin = false, balancer = false, ...rest } = options ?? {};

const cookieStore = cookies();

Expand All @@ -53,35 +54,35 @@ export const createClient = (options?: CreateClientOptions) => {
}
: {};

return createServerClient<Database>(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
key,
{
...rest,
cookies: {
get(name: string) {
return cookieStore.get(name)?.value;
},
set(name: string, value: string, options: CookieOptions) {
try {
cookieStore.set({ name, value, ...options });
} catch (error) {}
},
remove(name: string, options: CookieOptions) {
try {
cookieStore.set({ name, value: "", ...options });
} catch (error) {}
},
const url = balancer
? process.env.NEXT_PUBLIC_SUPABASE_LOAD_BALANCER_URL!
: process.env.NEXT_PUBLIC_SUPABASE_URL!;

return createServerClient<Database>(url, key, {
...rest,
cookies: {
get(name: string) {
return cookieStore.get(name)?.value;
},
set(name: string, value: string, options: CookieOptions) {
try {
cookieStore.set({ name, value, ...options });
} catch (error) {}
},
auth,
global: {
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",
},
remove(name: string, options: CookieOptions) {
try {
cookieStore.set({ name, value: "", ...options });
} catch (error) {}
},
},
);
auth,
global: {
headers: {
// Pass user agent from browser
"user-agent": headers().get("user-agent") as string,
// https://supabase.com/docs/guides/platform/read-replicas#experimental-routing
...(balancer && { "sb-lb-routing-mode": "alpha-all-services" }),
},
},
});
};
10 changes: 5 additions & 5 deletions packages/supabase/src/queries/cached-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ export const getUserInvites = async () => {
export const getTrackerProjects = async (
params: Omit<GetTrackerProjectsQueryParams, "teamId">,
) => {
const supabase = createClient();
const supabase = createClient({ balancer: true });
const user = await getUser();
const teamId = user?.data?.team_id;

Expand All @@ -361,7 +361,7 @@ export const getTrackerProjects = async (
export const getTrackerRecordsByRange = async (
params: Omit<GetTrackerRecordsByRangeParams, "teamId">,
) => {
const supabase = createClient();
const supabase = createClient({ balancer: true });
const user = await getUser();
const teamId = user?.data?.team_id;

Expand All @@ -384,7 +384,7 @@ export const getTrackerRecordsByRange = async (
export const getBurnRate = async (
params: Omit<GetBurnRateQueryParams, "teamId">,
) => {
const supabase = createClient();
const supabase = createClient({ balancer: true });
const user = await getUser();
const teamId = user?.data?.team_id;

Expand All @@ -403,7 +403,7 @@ export const getBurnRate = async (
export const getRunway = async (
params: Omit<GetRunwayQueryParams, "teamId">,
) => {
const supabase = createClient();
const supabase = createClient({ balancer: true });
const user = await getUser();
const teamId = user?.data?.team_id;

Expand All @@ -422,7 +422,7 @@ export const getRunway = async (
export const getCategories = async (
params?: Omit<GetCategoriesParams, "teamId">,
) => {
const supabase = createClient();
const supabase = createClient({ balancer: true });
const user = await getUser();
const teamId = user?.data?.team_id;

Expand Down

0 comments on commit 796e94a

Please sign in to comment.