diff --git a/src/app/admin/settings/user/page.tsx b/src/app/admin/settings/user/page.tsx index a015177..101f0c4 100644 --- a/src/app/admin/settings/user/page.tsx +++ b/src/app/admin/settings/user/page.tsx @@ -60,7 +60,7 @@ export default function UserProfilePage() { fetchUser(); }, [reset]); - const onSubmit: SubmitHandler = async (data) => { + const onSubmit: SubmitHandler = (data) => { startSavingTransition(async () => { const result = await updateUser({ name: data.name, @@ -73,7 +73,6 @@ export default function UserProfilePage() { title: "Profile Updated", description: "Your profile has been updated successfully.", }); - // Clear password fields and reset dirty state after successful submission reset({ ...data, password: '', confirmPassword: '' }); } else { toast({ diff --git a/src/lib/actions/user.ts b/src/lib/actions/user.ts index 34de759..2e96be8 100644 --- a/src/lib/actions/user.ts +++ b/src/lib/actions/user.ts @@ -32,7 +32,7 @@ export async function updateUser( data: z.infer ): Promise<{ success: boolean; error?: string }> { const session = await auth(); - if (!session?.user?.id) { + if (!session || !session.user || !session.user.id) { return { success: false, error: 'Not authenticated. Please log in again.' }; } @@ -44,17 +44,17 @@ export async function updateUser( } const { name, email, password } = validated.data; + const userId = session.user.id; try { - // In a real application, you should hash the password! if (password && password.trim().length > 0) { const stmt = db.prepare( 'UPDATE users SET name = ?, email = ?, password = ? WHERE id = ?' ); - stmt.run(name, email, password, session.user.id); + stmt.run(name, email, password, userId); } else { const stmt = db.prepare('UPDATE users SET name = ?, email = ? WHERE id = ?'); - stmt.run(name, email, session.user.id); + stmt.run(name, email, userId); } return { success: true }; } catch (error: any) {