diff --git a/src/app/(app)/profile/page.tsx b/src/app/(app)/profile/page.tsx index 9a79623..98faeea 100644 --- a/src/app/(app)/profile/page.tsx +++ b/src/app/(app)/profile/page.tsx @@ -6,28 +6,40 @@ import { useDevice } from "@/lib/context/DeviceContext"; function Mobile() { const { isAuthenticated, session } = useDevice(); const [bio, setBio] = useState(session?.bio || ""); + const [username, setUsername] = useState(session?.username || ""); useEffect(() => { if (session) { setBio(session.bio || ""); + setUsername(session.username || ""); } }, [session]); function handleSubmit(e: React.FormEvent) { e.preventDefault(); - if (bio.length > 0) { + if (bio.length > 0 || username.length > 0) { const formData = new FormData(); - formData.append("bio", bio); + if (bio.length > 0) formData.append("bio", bio); + if (username.length > 0) formData.append("username", username); fetch("/api/me", { method: "POST", body: formData, // Automatically sets Content-Type to multipart/form-data - }); - - // Show a success message - alert("Bio saved!"); + }) + .then((res) => res.json()) + .then((data) => { + if (data.message === "User updated successfully") { + alert("Profile updated successfully!"); + } else { + alert("Failed to update profile."); + } + }) + .catch((err) => { + console.error("Error updating profile:", err); + alert("An error occurred while updating your profile."); + }); } else { - alert("Please enter a bio."); + alert("Please enter a bio or username."); } } @@ -35,7 +47,7 @@ function Mobile() {

- Hi, {session?.username || ""}!! + Hi, {username || ""}!!

@@ -46,12 +58,19 @@ function Mobile() { className="w-42 h-42 rounded-full object-cover bg-surface-700" /> )} - {/* {uploadMessage && ( -

{uploadMessage}

- )} */}
-
+ + {/* Username Input */} + setUsername(e.target.value)} + value={username || ""} + placeholder="Update your username..." + /> + + {/* Bio Input */}