Adjust query to select the correct owner of the Team deleting the account
This commit is contained in:
@@ -175,6 +175,7 @@ function Home() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default withI18n(Home);
|
export default withI18n(Home);
|
||||||
|
|
||||||
function MainCallToActionButton() {
|
function MainCallToActionButton() {
|
||||||
|
|||||||
@@ -2,10 +2,7 @@
|
|||||||
|
|
||||||
import { redirect } from 'next/navigation';
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
import { SupabaseClient } from '@supabase/supabase-js';
|
|
||||||
|
|
||||||
import { enhanceAction } from '@kit/next/actions';
|
import { enhanceAction } from '@kit/next/actions';
|
||||||
import { Database } from '@kit/supabase/database';
|
|
||||||
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client';
|
||||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||||
|
|
||||||
@@ -18,12 +15,11 @@ export const deleteTeamAccountAction = enhanceAction(
|
|||||||
Object.fromEntries(formData.entries()),
|
Object.fromEntries(formData.entries()),
|
||||||
);
|
);
|
||||||
|
|
||||||
const client = getSupabaseServerClient();
|
|
||||||
const userId = user.id;
|
const userId = user.id;
|
||||||
const accountId = params.accountId;
|
const accountId = params.accountId;
|
||||||
|
|
||||||
// Check if the user has the necessary permissions to delete the team account
|
// Check if the user has the necessary permissions to delete the team account
|
||||||
await assertUserPermissionsToDeleteTeamAccount(client, {
|
await assertUserPermissionsToDeleteTeamAccount({
|
||||||
accountId,
|
accountId,
|
||||||
userId,
|
userId,
|
||||||
});
|
});
|
||||||
@@ -45,19 +41,19 @@ export const deleteTeamAccountAction = enhanceAction(
|
|||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
|
|
||||||
async function assertUserPermissionsToDeleteTeamAccount(
|
async function assertUserPermissionsToDeleteTeamAccount(params: {
|
||||||
client: SupabaseClient<Database>,
|
accountId: string;
|
||||||
params: {
|
userId: string;
|
||||||
accountId: string;
|
}) {
|
||||||
userId: string;
|
const client = getSupabaseServerClient();
|
||||||
},
|
|
||||||
) {
|
|
||||||
const { data, error } = await client
|
const { data, error } = await client
|
||||||
.from('accounts')
|
.from('accounts')
|
||||||
.select('id')
|
.select('id')
|
||||||
.eq('primary_owner_user_id', params.userId)
|
.eq('primary_owner_user_id', params.userId)
|
||||||
.eq('is_personal_account', false)
|
.eq('is_personal_account', false)
|
||||||
.eq('id', params.accountId);
|
.eq('id', params.accountId)
|
||||||
|
.single();
|
||||||
|
|
||||||
if (error ?? !data) {
|
if (error ?? !data) {
|
||||||
throw new Error('Account not found');
|
throw new Error('Account not found');
|
||||||
|
|||||||
Reference in New Issue
Block a user