same issue reoccus when tryinfg to change admin email and password, i ge

This commit is contained in:
Leon Serfaty G
2025-07-17 11:30:50 +00:00
parent 89cfc08a17
commit 431023f6ed
3 changed files with 28 additions and 14 deletions
+6 -4
View File
@@ -32,18 +32,20 @@ export async function updateUser(
): Promise<{ success: boolean; error?: string }> {
const session = await getSession();
if (!session?.userId) {
return { success: false, error: 'Not authenticated' };
return { success: false, error: 'Not authenticated. Please log in again.' };
}
const validated = UserUpdateSchema.safeParse(data);
if (!validated.success) {
return { success: false, error: 'Invalid data' };
const errors = validated.error.flatten().fieldErrors;
const firstError = Object.values(errors)[0]?.[0] ?? 'Invalid data provided.';
return { success: false, error: firstError };
}
const { name, email, password } = validated.data;
try {
if (password && password.length > 0) {
if (password && password.trim().length > 0) {
// In a real application, hash the password
const stmt = db.prepare(
'UPDATE users SET name = ?, email = ?, password = ? WHERE id = ?'
@@ -59,6 +61,6 @@ export async function updateUser(
if (error.code === 'SQLITE_CONSTRAINT_UNIQUE') {
return { success: false, error: 'Email already in use.' };
}
return { success: false, error: 'Failed to update user profile.' };
return { success: false, error: 'Failed to update user profile due to a server error.' };
}
}