error toast. could not load user profile

This commit is contained in:
Leon Serfaty G
2025-07-18 02:50:35 +00:00
parent e1586d9ed1
commit a49bd1d6e6
2 changed files with 14 additions and 9 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ export default async function AdminLayout({
</Link> </Link>
</SidebarMenuItem> </SidebarMenuItem>
<SidebarMenuItem> <SidebarMenuItem>
<Link href="/admin/embed" className="w-full"> <Link href="/admin/embed" className='w-full'>
<SidebarMenuButton> <SidebarMenuButton>
<Code2 /> <Code2 />
Embed Embed
+8 -3
View File
@@ -57,6 +57,14 @@ export async function updateUser(
const userId = session.user.id; const userId = session.user.id;
try { 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) { if (password && password.trim().length > 0) {
// In a real app, you would hash the password here // In a real app, you would hash the password here
const stmt = db.prepare( const stmt = db.prepare(
@@ -70,9 +78,6 @@ export async function updateUser(
return { success: true }; return { success: true };
} catch (error: any) { } catch (error: any) {
console.error('Failed to update user:', error); 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.' }; return { success: false, error: 'Failed to update user profile due to a server error.' };
} }
} }