From 445abc0762e5eafeffef8a8f813b05fd07e7767a Mon Sep 17 00:00:00 2001 From: Arhan Ansari Date: Sat, 26 Oct 2024 15:43:39 +0530 Subject: [PATCH] Update page.tsx --- app/profile/page.tsx | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/app/profile/page.tsx b/app/profile/page.tsx index cb15c36..2d2eba8 100644 --- a/app/profile/page.tsx +++ b/app/profile/page.tsx @@ -73,18 +73,19 @@ const ProfilePage = () => { }; const handleNameChange = async () => { - if (!user) return; - - try { - await updateProfile(user, { displayName: name }); - await updateUserData(user.email!, { name }); // Update name in Firestore - setNameEditMode(false); - alert("Name updated successfully!"); - } catch (error) { - console.error("Error updating name:", error); - alert("Failed to update name. Please try again."); - } - }; + if (!user) return; + + try { + await updateProfile(user, { displayName: name }); + // Update name in Firestore as part of the userData object + await updateUserData(user.email!, { ...userData, name }); + setNameEditMode(false); + alert("Name updated successfully!"); + } catch (error) { + console.error("Error updating name:", error); + alert("Failed to update name. Please try again."); + } +}; const handleSignOut = () => { signOut(auth).catch((error) => console.error("Sign out error:", error));