Refactored Supabase Clients using the new recommended approach by Supabase by centralizing all clients around one single implementation. (#51)
The previous clients have been marked as deprecated and will be removed at some point.
This commit is contained in:
committed by
GitHub
parent
2f0c4b4ae3
commit
ba6e649461
@@ -1,7 +1,7 @@
|
||||
import { cache } from 'react';
|
||||
|
||||
import { createAccountsApi } from '@kit/accounts/api';
|
||||
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import featureFlagsConfig from '~/config/feature-flags.config';
|
||||
import { requireUserInServerComponent } from '~/lib/server/require-user-in-server-component';
|
||||
@@ -19,7 +19,7 @@ export type UserWorkspace = Awaited<ReturnType<typeof loadUserWorkspace>>;
|
||||
export const loadUserWorkspace = cache(workspaceLoader);
|
||||
|
||||
async function workspaceLoader() {
|
||||
const client = getSupabaseServerComponentClient();
|
||||
const client = getSupabaseServerClient();
|
||||
const api = createAccountsApi(client);
|
||||
|
||||
const accountsPromise = shouldLoadAccounts
|
||||
|
||||
@@ -5,7 +5,7 @@ import { cache } from 'react';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { createAccountsApi } from '@kit/accounts/api';
|
||||
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
/**
|
||||
* The variable BILLING_MODE represents the billing mode for a service. It can
|
||||
@@ -33,7 +33,7 @@ export const loadPersonalAccountBillingPageData = cache(
|
||||
);
|
||||
|
||||
function personalAccountBillingPageDataLoader(userId: string) {
|
||||
const client = getSupabaseServerComponentClient();
|
||||
const client = getSupabaseServerClient();
|
||||
const api = createAccountsApi(client);
|
||||
|
||||
const data =
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import { enhanceAction } from '@kit/next/actions';
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import featureFlagsConfig from '~/config/feature-flags.config';
|
||||
|
||||
@@ -26,7 +26,7 @@ export const createPersonalAccountCheckoutSession = enhanceAction(
|
||||
throw new Error('Personal account billing is not enabled');
|
||||
}
|
||||
|
||||
const client = getSupabaseServerActionClient();
|
||||
const client = getSupabaseServerClient();
|
||||
const service = createUserBillingService(client);
|
||||
|
||||
return await service.createCheckoutSession(data);
|
||||
@@ -46,7 +46,7 @@ export const createPersonalAccountBillingPortalSession = enhanceAction(
|
||||
throw new Error('Personal account billing is not enabled');
|
||||
}
|
||||
|
||||
const client = getSupabaseServerActionClient();
|
||||
const client = getSupabaseServerClient();
|
||||
const service = createUserBillingService(client);
|
||||
|
||||
// get url to billing portal
|
||||
|
||||
@@ -4,7 +4,7 @@ import { cache } from 'react';
|
||||
|
||||
import { z } from 'zod';
|
||||
|
||||
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
import { createTeamAccountsApi } from '@kit/team-accounts/api';
|
||||
|
||||
/**
|
||||
@@ -29,7 +29,7 @@ const BILLING_MODE = z
|
||||
export const loadTeamAccountBillingPage = cache(teamAccountBillingPageLoader);
|
||||
|
||||
function teamAccountBillingPageLoader(accountId: string) {
|
||||
const client = getSupabaseServerComponentClient();
|
||||
const client = getSupabaseServerClient();
|
||||
const api = createTeamAccountsApi(client);
|
||||
|
||||
const data =
|
||||
|
||||
@@ -4,7 +4,7 @@ import { cache } from 'react';
|
||||
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
import { createTeamAccountsApi } from '@kit/team-accounts/api';
|
||||
|
||||
import pathsConfig from '~/config/paths.config';
|
||||
@@ -26,7 +26,7 @@ export type TeamAccountWorkspace = Awaited<
|
||||
export const loadTeamWorkspace = cache(workspaceLoader);
|
||||
|
||||
async function workspaceLoader(accountSlug: string) {
|
||||
const client = getSupabaseServerComponentClient();
|
||||
const client = getSupabaseServerClient();
|
||||
const api = createTeamAccountsApi(client);
|
||||
|
||||
const [workspace, user] = await Promise.all([
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import { enhanceAction } from '@kit/next/actions';
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import featureFlagsConfig from '~/config/feature-flags.config';
|
||||
|
||||
@@ -30,7 +30,7 @@ export const createTeamAccountCheckoutSession = enhanceAction(
|
||||
throw new Error('Team account billing is not enabled');
|
||||
}
|
||||
|
||||
const client = getSupabaseServerActionClient();
|
||||
const client = getSupabaseServerClient();
|
||||
const service = createTeamBillingService(client);
|
||||
|
||||
return service.createCheckout(data);
|
||||
@@ -53,7 +53,7 @@ export const createBillingPortalSession = enhanceAction(
|
||||
|
||||
const params = TeamBillingPortalSchema.parse(Object.fromEntries(formData));
|
||||
|
||||
const client = getSupabaseServerActionClient();
|
||||
const client = getSupabaseServerClient();
|
||||
const service = createTeamBillingService(client);
|
||||
|
||||
// get url to billing portal
|
||||
|
||||
@@ -8,7 +8,7 @@ import { LineItemSchema } from '@kit/billing';
|
||||
import { getBillingGatewayProvider } from '@kit/billing-gateway';
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
import { requireUser } from '@kit/supabase/require-user';
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
import { createTeamAccountsApi } from '@kit/team-accounts/api';
|
||||
|
||||
import appConfig from '~/config/app.config';
|
||||
@@ -150,7 +150,7 @@ class TeamBillingService {
|
||||
accountId: string;
|
||||
slug: string;
|
||||
}) {
|
||||
const client = getSupabaseServerActionClient();
|
||||
const client = getSupabaseServerClient();
|
||||
const logger = await getLogger();
|
||||
|
||||
logger.info(
|
||||
|
||||
@@ -4,7 +4,7 @@ import { notFound, redirect } from 'next/navigation';
|
||||
|
||||
import { getBillingGatewayProvider } from '@kit/billing-gateway';
|
||||
import { BillingSessionStatus } from '@kit/billing-gateway/components';
|
||||
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import billingConfig from '~/config/billing.config';
|
||||
import { withI18n } from '~/lib/i18n/with-i18n';
|
||||
@@ -75,7 +75,7 @@ function BlurryBackdrop() {
|
||||
async function loadCheckoutSession(sessionId: string) {
|
||||
await requireUserInServerComponent();
|
||||
|
||||
const client = getSupabaseServerComponentClient();
|
||||
const client = getSupabaseServerClient();
|
||||
const gateway = await getBillingGatewayProvider(client);
|
||||
|
||||
const session = await gateway.retrieveCheckoutSession({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { PlusCircle } from 'lucide-react';
|
||||
|
||||
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
import {
|
||||
AccountInvitationsTable,
|
||||
AccountMembersTable,
|
||||
@@ -42,7 +42,7 @@ export const generateMetadata = async () => {
|
||||
};
|
||||
|
||||
async function TeamAccountMembersPage({ params }: Params) {
|
||||
const client = getSupabaseServerComponentClient();
|
||||
const client = getSupabaseServerClient();
|
||||
|
||||
const [members, invitations, canAddMember, { user, account }] =
|
||||
await loadMembersPageData(client, params.account);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
import { createTeamAccountsApi } from '@kit/team-accounts/api';
|
||||
import { TeamAccountSettingsContainer } from '@kit/team-accounts/components';
|
||||
import { AppBreadcrumbs } from '@kit/ui/app-breadcrumbs';
|
||||
@@ -32,7 +32,7 @@ const paths = {
|
||||
};
|
||||
|
||||
async function TeamAccountSettingsPage(props: Props) {
|
||||
const api = createTeamAccountsApi(getSupabaseServerComponentClient());
|
||||
const api = createTeamAccountsApi(getSupabaseServerClient());
|
||||
const data = await api.getTeamAccount(props.params.account);
|
||||
|
||||
const account = {
|
||||
|
||||
Reference in New Issue
Block a user