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
-7
View File
@@ -1,4 +1,3 @@
"use client"; "use client";
import { useForm, type SubmitHandler } from "react-hook-form"; import { useForm, type SubmitHandler } from "react-hook-form";
@@ -42,12 +41,6 @@ export default function UserProfilePage() {
formState: { errors, isDirty }, formState: { errors, isDirty },
} = useForm<UserProfileFormValues>({ } = useForm<UserProfileFormValues>({
resolver: zodResolver(userProfileSchema), resolver: zodResolver(userProfileSchema),
defaultValues: {
name: "",
email: "",
password: "",
confirmPassword: ""
}
}); });
useEffect(() => { useEffect(() => {
+3 -3
View File
@@ -1,4 +1,3 @@
'use server'; 'use server';
import db from '@/lib/db'; import db from '@/lib/db';
@@ -32,7 +31,7 @@ export async function updateUser(
data: z.infer<typeof UserUpdateSchema> data: z.infer<typeof UserUpdateSchema>
): Promise<{ success: boolean; error?: string }> { ): Promise<{ success: boolean; error?: string }> {
const session = await auth(); 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.' }; return { success: false, error: 'Not authenticated. Please log in again.' };
} }
@@ -47,6 +46,7 @@ export async function updateUser(
const userId = session.user.id; const userId = session.user.id;
try { try {
// Note: In a real production app, password should be hashed!
if (password && password.trim().length > 0) { if (password && password.trim().length > 0) {
const stmt = db.prepare( const stmt = db.prepare(
'UPDATE users SET name = ?, email = ?, password = ? WHERE id = ?' 'UPDATE users SET name = ?, email = ?, password = ? WHERE id = ?'
@@ -60,7 +60,7 @@ export async function updateUser(
} 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') { 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.' }; return { success: false, error: 'Failed to update user profile due to a server error.' };
} }