error toast. could not load user profile
This commit is contained in:
@@ -57,6 +57,14 @@ export async function updateUser(
|
||||
const userId = session.user.id;
|
||||
|
||||
try {
|
||||
// Check if another user with the same email exists
|
||||
const existingUserStmt = db.prepare('SELECT id FROM users WHERE email = ? AND id != ?');
|
||||
const existingUser = existingUserStmt.get(email, userId);
|
||||
|
||||
if (existingUser) {
|
||||
return { success: false, error: 'Email already in use by another account.' };
|
||||
}
|
||||
|
||||
if (password && password.trim().length > 0) {
|
||||
// In a real app, you would hash the password here
|
||||
const stmt = db.prepare(
|
||||
@@ -70,9 +78,6 @@ export async function updateUser(
|
||||
return { success: true };
|
||||
} catch (error: any) {
|
||||
console.error('Failed to update user:', error);
|
||||
if (error.code === 'SQLITE_CONSTRAINT_UNIQUE') {
|
||||
return { success: false, error: 'Email already in use by another account.' };
|
||||
}
|
||||
return { success: false, error: 'Failed to update user profile due to a server error.' };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user