Update account management features and improve test configurations
Multiple updates are made to refine the account management features, including updating the 'Your Teams' text to show the number of teams, and modifying the form data validation process in the 'deletePersonalAccountAction' service. Additionally, improvements have been made in test configurations including updating the test timeout settings, taking screenshots when a test fails, and adjusting the location for saving Playwright reports.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
'use server';
|
||||
|
||||
import { revalidatePath } from 'next/cache';
|
||||
import { RedirectType, redirect } from 'next/navigation';
|
||||
|
||||
import { z } from 'zod';
|
||||
@@ -8,6 +9,7 @@ import { getLogger } from '@kit/shared/logger';
|
||||
import { requireUser } from '@kit/supabase/require-user';
|
||||
import { getSupabaseServerActionClient } from '@kit/supabase/server-actions-client';
|
||||
|
||||
import { DeletePersonalAccountSchema } from '../schema/delete-personal-account.schema';
|
||||
import { DeletePersonalAccountService } from './services/delete-personal-account.service';
|
||||
|
||||
const emailSettings = getEmailSettingsFromEnvironment();
|
||||
@@ -21,10 +23,13 @@ export async function refreshAuthSession() {
|
||||
}
|
||||
|
||||
export async function deletePersonalAccountAction(formData: FormData) {
|
||||
const confirmation = formData.get('confirmation');
|
||||
// validate the form data
|
||||
const { success } = DeletePersonalAccountSchema.safeParse(
|
||||
Object.fromEntries(formData.entries()),
|
||||
);
|
||||
|
||||
if (confirmation !== 'DELETE') {
|
||||
throw new Error('Confirmation required to delete account');
|
||||
if (!success) {
|
||||
throw new Error('Invalid form data');
|
||||
}
|
||||
|
||||
const client = getSupabaseServerActionClient();
|
||||
@@ -32,7 +37,13 @@ export async function deletePersonalAccountAction(formData: FormData) {
|
||||
|
||||
if (auth.error) {
|
||||
const logger = await getLogger();
|
||||
logger.error(`User is not authenticated. Redirecting to login page`);
|
||||
|
||||
logger.error(
|
||||
{
|
||||
error: auth.error,
|
||||
},
|
||||
`User is not authenticated. Redirecting to login page.`,
|
||||
);
|
||||
|
||||
redirect(auth.redirectTo);
|
||||
}
|
||||
@@ -55,6 +66,8 @@ export async function deletePersonalAccountAction(formData: FormData) {
|
||||
// sign out the user after deleting their account
|
||||
await client.auth.signOut();
|
||||
|
||||
revalidatePath('/', 'layout');
|
||||
|
||||
// redirect to the home page
|
||||
redirect('/', RedirectType.replace);
|
||||
}
|
||||
|
||||
@@ -35,11 +35,15 @@ export class DeletePersonalAccountService {
|
||||
productName: string;
|
||||
};
|
||||
}) {
|
||||
const userId = params.userId;
|
||||
const logger = await getLogger();
|
||||
|
||||
const userId = params.userId;
|
||||
const ctx = { userId, name: this.namespace };
|
||||
|
||||
logger.info(ctx, 'User requested deletion. Processing...');
|
||||
logger.info(
|
||||
ctx,
|
||||
'User requested to delete their personal account. Processing...',
|
||||
);
|
||||
|
||||
// execute the deletion of the user
|
||||
try {
|
||||
@@ -50,12 +54,12 @@ export class DeletePersonalAccountService {
|
||||
...ctx,
|
||||
error,
|
||||
},
|
||||
'Error deleting user',
|
||||
'Encountered an error deleting user',
|
||||
);
|
||||
|
||||
throw new Error('Error deleting user');
|
||||
}
|
||||
|
||||
logger.info(ctx, 'User deleted successfully');
|
||||
logger.info(ctx, 'User successfully deleted!');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user