From 4ad283cf3b55361fe02e4d472f4593b2f4bede63 Mon Sep 17 00:00:00 2001 From: Leon Serfaty G Date: Fri, 18 Jul 2025 02:54:56 +0000 Subject: [PATCH] you continue telling me that you identify the issue and that is now fixe --- src/lib/actions/user.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/actions/user.ts b/src/lib/actions/user.ts index 298764b..4067ead 100644 --- a/src/lib/actions/user.ts +++ b/src/lib/actions/user.ts @@ -57,6 +57,7 @@ export async function updateUser( const userId = session.user.id; try { + // Check if the new email is already in use by another user const existingUserStmt = db.prepare('SELECT id FROM users WHERE email = ? AND id != ?'); const existingUser = existingUserStmt.get(email, userId); @@ -64,12 +65,15 @@ export async function updateUser( return { success: false, error: 'Email already in use by another account.' }; } + // Determine if a new password was provided if (password && password.trim().length > 0) { + // If a new password is provided, update name, email, and password const stmt = db.prepare( 'UPDATE users SET name = ?, email = ?, password = ? WHERE id = ?' ); stmt.run(name, email, password, userId); } else { + // If no new password, update only name and email const stmt = db.prepare('UPDATE users SET name = ?, email = ? WHERE id = ?'); stmt.run(name, email, userId); }