is not even saving the inputs

This commit is contained in:
Leon Serfaty G
2025-07-17 11:38:42 +00:00
parent bb11434141
commit 549f189370
2 changed files with 3 additions and 10 deletions
+3 -3
View File
@@ -1,4 +1,3 @@
'use server';
import db from '@/lib/db';
@@ -32,7 +31,7 @@ export async function updateUser(
data: z.infer<typeof UserUpdateSchema>
): Promise<{ success: boolean; error?: string }> {
const session = await auth();
if (!session || !session.user || !session.user.id) {
if (!session?.user?.id) {
return { success: false, error: 'Not authenticated. Please log in again.' };
}
@@ -47,6 +46,7 @@ export async function updateUser(
const userId = session.user.id;
try {
// Note: In a real production app, password should be hashed!
if (password && password.trim().length > 0) {
const stmt = db.prepare(
'UPDATE users SET name = ?, email = ?, password = ? WHERE id = ?'
@@ -60,7 +60,7 @@ export async function updateUser(
} catch (error: any) {
console.error('Failed to update user:', error);
if (error.code === 'SQLITE_CONSTRAINT_UNIQUE') {
return { success: false, error: 'Email already in use.' };
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.' };
}