Index: app/(app)/profile/actions.ts
===================================================================
--- app/(app)/profile/actions.ts	(revision f20977e9ce332fa167b0afc1e9415dcfc0a4f09a)
+++ app/(app)/profile/actions.ts	(revision 82cef6ab997fdcac4747fa881f82b9117036e544)
@@ -8,16 +8,37 @@
 const sql = postgres(process.env.POSTGRES_URL!, { ssl: 'require' });
 
-export async function updateProfile(formData: FormData) {
+type ActionResult = string | undefined; // string = error message, undefined = success
+
+export async function updateProfile(
+    _prevState: ActionResult,
+    formData: FormData
+): Promise<ActionResult> {
     const session = await auth();
-
-    const userId = Number(session?.user?.id);
-    if (!Number.isInteger(userId)) {
-        throw new Error('Invalid user ID in session');
+    if (!session?.user?.id) {
+        redirect('/login');
     }
 
-    if (!session?.user?.id) redirect('/login');
+    const userId = Number(session.user.id);
+    if (!Number.isInteger(userId)) {
+        return 'Invalid session. Please log in again.';
+    }
+    const name = String(formData.get('name') ?? '').trim();
+    const email = String(formData.get('email') ?? '').trim().toLowerCase();
 
-    const name = formData.get('name') as string;
-    const email = formData.get('email') as string;
+    if (!name) {
+        return 'Name is required.';
+    }
+    if (!email || !email.includes('@')) {
+        return 'Please enter a valid email.';
+    }
+
+    // Email already exists check
+    const existing = await sql`
+        SELECT user_id FROM "user"
+        WHERE email = ${email} AND user_id != ${userId}
+    `;
+    if (existing.length > 0) {
+        return 'Email already exists.';
+    }
 
     await sql`
@@ -31,16 +52,23 @@
 }
 
-export async function updatePassword(formData: FormData) {
+export async function updatePassword(
+    _prevState: ActionResult,
+    formData: FormData
+): Promise<ActionResult> {
     const session = await auth();
-
-    const userId = Number(session?.user?.id);
-    if (!Number.isInteger(userId)) {
-        throw new Error('Invalid user ID in session');
+    if (!session?.user?.id) {
+        redirect('/login');
     }
 
-    if (!session?.user?.id) redirect('/login');
+    const userId = Number(session.user.id);
+    if (!Number.isInteger(userId)) {
+        return 'Invalid session. Please log in again.';
+    }
+    const currentPassword = String(formData.get('currentPassword') ?? '');
+    const newPassword = String(formData.get('newPassword') ?? '');
 
-    const currentPassword = formData.get('currentPassword') as string;
-    const newPassword = formData.get('newPassword') as string;
+    if (newPassword.length < 6) {
+        return 'New password must be at least 6 characters.';
+    }
 
     const users = await sql`
@@ -49,11 +77,12 @@
         WHERE user_id = ${userId}
     `;
-
     const user = users[0];
-    if (!user) redirect('/login');
+    if (!user) {
+        return 'User not found. Please log in again.';
+    }
 
     const match = await bcrypt.compare(currentPassword, user.password);
     if (!match) {
-        throw new Error('Current password is incorrect');
+        return 'Current password is incorrect.';
     }
 
Index: app/(app)/profile/page.tsx
===================================================================
--- app/(app)/profile/page.tsx	(revision f20977e9ce332fa167b0afc1e9415dcfc0a4f09a)
+++ app/(app)/profile/page.tsx	(revision 82cef6ab997fdcac4747fa881f82b9117036e544)
@@ -2,9 +2,8 @@
 import { redirect } from 'next/navigation';
 import { poppins } from '@/app/ui/fonts';
-import { updateProfile, updatePassword } from './actions';
+import { ProfileUpdateForm, PasswordUpdateForm } from './profile-forms';
 
 export default async function ProfilePage() {
     const session = await auth();
-
     if (!session?.user) {
         redirect('/login');
@@ -13,5 +12,4 @@
     return (
         <div className="w-full px-6 pt-10 space-y-10">
-            {/* Title */}
             <h1
                 className={`${poppins.className}
@@ -28,67 +26,15 @@
 
             <div className="max-w-md mx-auto space-y-8 pb-10">
-
                 {/* Account Info */}
                 <section className="rounded-3xl bg-white/5 backdrop-blur-md border border-white/10 p-6 space-y-5">
-
-                    <form action={updateProfile} className="space-y-4">
-                        <div className="space-y-2">
-                            <label className="text-white/70 text-sm">Name</label>
-                            <input
-                                name="name"
-                                defaultValue={session.user.name ?? ''}
-                                required
-                                className="w-full rounded-xl bg-white/10 border border-white/10 px-4 py-3 text-white focus:ring-2 focus:ring-blue-500 outline-none"
-                            />
-                        </div>
-
-                        <div className="space-y-2">
-                            <label className="text-white/70 text-sm">Email</label>
-                            <input
-                                name="email"
-                                defaultValue={session.user.email ?? ''}
-                                required
-                                className="w-full rounded-xl bg-white/10 border border-white/10 px-4 py-3 text-white focus:ring-2 focus:ring-blue-500 outline-none"
-                            />
-                        </div>
-
-                        <button className="w-full bg-blue-600 hover:bg-blue-500 rounded-xl py-3 text-white font-medium transition">
-                            Save Changes
-                        </button>
-                    </form>
+                    <ProfileUpdateForm
+                        defaultName={session.user.name ?? ''}
+                        defaultEmail={session.user.email ?? ''}
+                    />
                 </section>
 
                 {/* Security */}
                 <section className="rounded-3xl bg-white/5 backdrop-blur-md border border-white/10 p-6 space-y-5">
-
-                    <form action={updatePassword} className="space-y-4">
-                        <div className="space-y-2">
-                            <label className="text-white/70 text-sm">
-                                Current Password
-                            </label>
-                            <input
-                                type="password"
-                                name="currentPassword"
-                                required
-                                className="w-full rounded-xl bg-white/10 border border-white/10 px-4 py-3 text-white focus:ring-2 focus:ring-blue-500 outline-none"
-                            />
-                        </div>
-
-                        <div className="space-y-2">
-                            <label className="text-white/70 text-sm">
-                                New Password
-                            </label>
-                            <input
-                                type="password"
-                                name="newPassword"
-                                required
-                                className="w-full rounded-xl bg-white/10 border border-white/10 px-4 py-3 text-white focus:ring-2 focus:ring-blue-500 outline-none"
-                            />
-                        </div>
-
-                        <button className="w-full bg-blue-600 hover:bg-blue-500 rounded-xl py-3 text-white font-medium transition">
-                            Update Password
-                        </button>
-                    </form>
+                    <PasswordUpdateForm />
                 </section>
 
@@ -104,5 +50,4 @@
                     </button>
                 </form>
-
             </div>
         </div>
Index: app/(app)/profile/profile-forms.tsx
===================================================================
--- app/(app)/profile/profile-forms.tsx	(revision 82cef6ab997fdcac4747fa881f82b9117036e544)
+++ app/(app)/profile/profile-forms.tsx	(revision 82cef6ab997fdcac4747fa881f82b9117036e544)
@@ -0,0 +1,98 @@
+'use client';
+
+import React from 'react';
+import { updateProfile, updatePassword } from './actions';
+
+function ErrorLine({ error }: { error?: string }) {
+    if (!error) {
+        return null;
+    }
+    return <p className="text-red-400 text-sm">{error}</p>;
+}
+
+export function ProfileUpdateForm({
+    defaultName,
+    defaultEmail,
+}: {
+    defaultName: string;
+    defaultEmail: string;
+}) {
+    const [error, action, pending] = React.useActionState<string | undefined, FormData>(
+        updateProfile,
+        undefined
+    );
+
+    return (
+        <form action={action} className="space-y-4">
+            <div className="space-y-2">
+                <label className="text-white/70 text-sm">Name</label>
+                <input
+                    name="name"
+                    defaultValue={defaultName}
+                    required
+                    className="w-full rounded-xl bg-white/10 border border-white/10 px-4 py-3 text-white focus:ring-2 focus:ring-blue-500 outline-none"
+                />
+            </div>
+
+            <div className="space-y-2">
+                <label className="text-white/70 text-sm">Email</label>
+                <input
+                    name="email"
+                    defaultValue={defaultEmail}
+                    required
+                    className="w-full rounded-xl bg-white/10 border border-white/10 px-4 py-3 text-white focus:ring-2 focus:ring-blue-500 outline-none"
+                />
+            </div>
+
+            <ErrorLine error={error} />
+
+            <button
+                disabled={pending}
+                className="w-full bg-blue-600 hover:bg-blue-500 rounded-xl py-3 text-white font-medium transition disabled:opacity-50 disabled:cursor-not-allowed"
+            >
+                {pending ? 'Saving…' : 'Save Changes'}
+            </button>
+        </form>
+    );
+}
+
+export function PasswordUpdateForm() {
+    const [error, action, pending] = React.useActionState<string | undefined, FormData>(
+        updatePassword,
+        undefined
+    );
+
+    return (
+        <form action={action} className="space-y-4">
+            <div className="space-y-2">
+                <label className="text-white/70 text-sm">Current Password</label>
+                <input
+                    type="password"
+                    name="currentPassword"
+                    required
+                    className="w-full rounded-xl bg-white/10 border border-white/10 px-4 py-3 text-white focus:ring-2 focus:ring-blue-500 outline-none"
+                />
+            </div>
+
+            <div className="space-y-2">
+                <label className="text-white/70 text-sm">New Password</label>
+                <input
+                    type="password"
+                    name="newPassword"
+                    required
+                    minLength={6}
+                    className="w-full rounded-xl bg-white/10 border border-white/10 px-4 py-3 text-white focus:ring-2 focus:ring-blue-500 outline-none"
+                />
+            </div>
+
+            <ErrorLine error={error} />
+
+            <button
+                disabled={pending}
+                className="w-full bg-blue-600 hover:bg-blue-500 rounded-xl py-3 text-white font-medium transition disabled:opacity-50 disabled:cursor-not-allowed"
+            >
+                {pending ? 'Updating…' : 'Update Password'}
+            </button>
+        </form>
+    );
+}
