Refactor Supabase client usage
Replaced various Supabase client imports with standardized admin and server clients across multiple files. This change ensures consistent and appropriate usage of admin and non-admin Supabase clients in server actions and services.
This commit is contained in:
@@ -5,8 +5,8 @@ import { ArrowLeft } from 'lucide-react';
|
||||
|
||||
import { AuthLayoutShell } from '@kit/auth/shared';
|
||||
import { requireUser } from '@kit/supabase/require-user';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
import { createTeamAccountsApi } from '@kit/team-accounts/api';
|
||||
import { AcceptInvitationContainer } from '@kit/team-accounts/components';
|
||||
import { Button } from '@kit/ui/button';
|
||||
|
||||
@@ -5,7 +5,7 @@ import { cache } from 'react';
|
||||
import { redirect } from 'next/navigation';
|
||||
|
||||
import { requireUser } from '@kit/supabase/require-user';
|
||||
import { getSupabaseServerComponentClient } from '@kit/supabase/server-component-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
/**
|
||||
* @name requireUserInServerComponent
|
||||
@@ -14,7 +14,7 @@ import { getSupabaseServerComponentClient } from '@kit/supabase/server-component
|
||||
* Use this instead of `requireUser` in server components, so you don't need to hit the database multiple times in a single request.
|
||||
*/
|
||||
export const requireUserInServerComponent = cache(async () => {
|
||||
const client = getSupabaseServerComponentClient();
|
||||
const client = getSupabaseServerClient();
|
||||
const result = await requireUser(client);
|
||||
|
||||
if (result.error) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import 'server-only';
|
||||
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
import { getSupabaseRouteHandlerClient } from '@kit/supabase/route-handler-client';
|
||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||
|
||||
import { RecordChange, Tables } from '../record-change.type';
|
||||
import { createDatabaseWebhookRouterService } from './database-webhook-router.service';
|
||||
@@ -59,16 +59,12 @@ class DatabaseWebhookHandlerService {
|
||||
|
||||
await verifier.verifySignatureOrThrow(request);
|
||||
|
||||
// all good, handle the webhook
|
||||
// all good, we can now the webhook
|
||||
|
||||
// create a client with admin access since we are handling webhooks
|
||||
// and no user is authenticated
|
||||
const client = getSupabaseRouteHandlerClient({
|
||||
admin: true,
|
||||
});
|
||||
// create a client with admin access since we are handling webhooks and no user is authenticated
|
||||
const adminClient = getSupabaseServerAdminClient();
|
||||
|
||||
// handle the webhook
|
||||
const service = createDatabaseWebhookRouterService(client);
|
||||
const service = createDatabaseWebhookRouterService(adminClient);
|
||||
|
||||
try {
|
||||
// handle the webhook event based on the table
|
||||
|
||||
@@ -6,8 +6,9 @@ import { redirect } from 'next/navigation';
|
||||
import { z } from 'zod';
|
||||
|
||||
import { enhanceAction } from '@kit/next/actions';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import { DeletePersonalAccountSchema } from '../schema/delete-personal-account.schema';
|
||||
import { createDeletePersonalAccountService } from './services/delete-personal-account.service';
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import { redirect } from 'next/navigation';
|
||||
|
||||
import { enhanceAction } from '@kit/next/actions';
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import {
|
||||
BanUserSchema,
|
||||
|
||||
@@ -6,7 +6,8 @@ import { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { enhanceAction } from '@kit/next/actions';
|
||||
import { Database } from '@kit/supabase/database';
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import { DeleteTeamAccountSchema } from '../../schema/delete-team-account.schema';
|
||||
import { createDeleteTeamAccountService } from '../services/delete-team-account.service';
|
||||
@@ -17,7 +18,7 @@ export const deleteTeamAccountAction = enhanceAction(
|
||||
Object.fromEntries(formData.entries()),
|
||||
);
|
||||
|
||||
const client = getSupabaseServerActionClient();
|
||||
const client = getSupabaseServerClient();
|
||||
const userId = user.id;
|
||||
const accountId = params.accountId;
|
||||
|
||||
@@ -30,16 +31,14 @@ export const deleteTeamAccountAction = enhanceAction(
|
||||
// Get the Supabase client and create a new service instance.
|
||||
const service = createDeleteTeamAccountService();
|
||||
|
||||
// Get the Supabase admin client.
|
||||
const adminClient = getSupabaseServerAdminClient();
|
||||
|
||||
// Delete the team account and all associated data.
|
||||
await service.deleteTeamAccount(
|
||||
getSupabaseServerActionClient({
|
||||
admin: true,
|
||||
}),
|
||||
{
|
||||
accountId,
|
||||
userId,
|
||||
},
|
||||
);
|
||||
await service.deleteTeamAccount(adminClient, {
|
||||
accountId,
|
||||
userId,
|
||||
});
|
||||
|
||||
return redirect('/home');
|
||||
},
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
import { revalidatePath } from 'next/cache';
|
||||
|
||||
import { enhanceAction } from '@kit/next/actions';
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import { RemoveMemberSchema } from '../../schema/remove-member.schema';
|
||||
import { TransferOwnershipConfirmationSchema } from '../../schema/transfer-ownership-confirmation.schema';
|
||||
@@ -16,7 +17,7 @@ import { createAccountMembersService } from '../services/account-members.service
|
||||
*/
|
||||
export const removeMemberFromAccountAction = enhanceAction(
|
||||
async ({ accountId, userId }) => {
|
||||
const client = getSupabaseServerActionClient();
|
||||
const client = getSupabaseServerClient();
|
||||
const service = createAccountMembersService(client);
|
||||
|
||||
await service.removeMemberFromAccount({
|
||||
@@ -40,9 +41,9 @@ export const removeMemberFromAccountAction = enhanceAction(
|
||||
*/
|
||||
export const updateMemberRoleAction = enhanceAction(
|
||||
async (data) => {
|
||||
const client = getSupabaseServerActionClient();
|
||||
const client = getSupabaseServerClient();
|
||||
const service = createAccountMembersService(client);
|
||||
const adminClient = getSupabaseServerActionClient({ admin: true });
|
||||
const adminClient = getSupabaseServerAdminClient();
|
||||
|
||||
// update the role of the member
|
||||
await service.updateMemberRole(data, adminClient);
|
||||
@@ -63,7 +64,7 @@ export const updateMemberRoleAction = enhanceAction(
|
||||
*/
|
||||
export const transferOwnershipAction = enhanceAction(
|
||||
async (data) => {
|
||||
const client = getSupabaseServerActionClient();
|
||||
const client = getSupabaseServerClient();
|
||||
|
||||
// assert that the user is the owner of the account
|
||||
const { data: isOwner, error } = await client.rpc('is_account_owner', {
|
||||
@@ -80,7 +81,7 @@ export const transferOwnershipAction = enhanceAction(
|
||||
|
||||
// at this point, the user is authenticated and is the owner of the account
|
||||
// so we proceed with the transfer of ownership with admin privileges
|
||||
const adminClient = getSupabaseServerActionClient({ admin: true });
|
||||
const adminClient = getSupabaseServerAdminClient();
|
||||
|
||||
// transfer the ownership of the account
|
||||
await service.transferOwnership(data, adminClient);
|
||||
|
||||
@@ -24,7 +24,7 @@ export function useBaselime(): MonitoringService {
|
||||
},
|
||||
ready() {
|
||||
return Promise.resolve();
|
||||
}
|
||||
},
|
||||
} satisfies MonitoringService;
|
||||
}, [captureException, sendEvent, setUser]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user