Enforce deletion environment variables server side; added logging
This commit is contained in:
@@ -5,26 +5,50 @@ import { redirect } from 'next/navigation';
|
||||
import type { SupabaseClient } from '@supabase/supabase-js';
|
||||
|
||||
import { enhanceAction } from '@kit/next/actions';
|
||||
import { getLogger } from '@kit/shared/logger';
|
||||
import type { Database } from '@kit/supabase/database';
|
||||
import { getSupabaseServerClient } from '@kit/supabase/server-client';
|
||||
|
||||
import { DeleteTeamAccountSchema } from '../../schema/delete-team-account.schema';
|
||||
import { createDeleteTeamAccountService } from '../services/delete-team-account.service';
|
||||
|
||||
const enableTeamAccountDeletion =
|
||||
process.env.NEXT_PUBLIC_ENABLE_TEAM_ACCOUNTS_DELETION === 'true';
|
||||
|
||||
export const deleteTeamAccountAction = enhanceAction(
|
||||
async (formData: FormData, user) => {
|
||||
const logger = await getLogger();
|
||||
|
||||
const params = DeleteTeamAccountSchema.parse(
|
||||
Object.fromEntries(formData.entries()),
|
||||
);
|
||||
|
||||
const ctx = {
|
||||
name: 'team-accounts.delete',
|
||||
userId: user.id,
|
||||
accountId: params.accountId,
|
||||
};
|
||||
|
||||
if (!enableTeamAccountDeletion) {
|
||||
logger.warn(ctx, `Team account deletion is not enabled`);
|
||||
|
||||
throw new Error('Team account deletion is not enabled');
|
||||
}
|
||||
|
||||
logger.info(ctx, `Deleting team account...`);
|
||||
|
||||
await deleteTeamAccount({
|
||||
accountId: params.accountId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
logger.info(ctx, `Team account request successfully sent`);
|
||||
|
||||
return redirect('/home');
|
||||
},
|
||||
{},
|
||||
{
|
||||
auth: true,
|
||||
},
|
||||
);
|
||||
|
||||
async function deleteTeamAccount(params: {
|
||||
|
||||
Reference in New Issue
Block a user