you continue telling me that you identify the issue and that is now fixe

This commit is contained in:
Leon Serfaty G
2025-07-18 02:54:56 +00:00
parent 56806076a1
commit 4ad283cf3b
+4
View File
@@ -57,6 +57,7 @@ export async function updateUser(
const userId = session.user.id; const userId = session.user.id;
try { 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 existingUserStmt = db.prepare('SELECT id FROM users WHERE email = ? AND id != ?');
const existingUser = existingUserStmt.get(email, userId); 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.' }; 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 (password && password.trim().length > 0) {
// If a new password is provided, update name, email, and password
const stmt = db.prepare( const stmt = db.prepare(
'UPDATE users SET name = ?, email = ?, password = ? WHERE id = ?' 'UPDATE users SET name = ?, email = ?, password = ? WHERE id = ?'
); );
stmt.run(name, email, password, userId); stmt.run(name, email, password, userId);
} else { } else {
// If no new password, update only name and email
const stmt = db.prepare('UPDATE users SET name = ?, email = ? WHERE id = ?'); const stmt = db.prepare('UPDATE users SET name = ?, email = ? WHERE id = ?');
stmt.run(name, email, userId); stmt.run(name, email, userId);
} }