same issue reoccus when tryinfg to change admin email and password, i ge
This commit is contained in:
@@ -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.' };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user