From 6ae03ca1e29de267cc3ed350a56cb8db44708821 Mon Sep 17 00:00:00 2001 From: khushboo-khatoon Date: Fri, 24 Jul 2026 11:54:45 +0530 Subject: [PATCH] separate error handling for account creation and profile update in signup --- frontend/components/signupform.tsx | 46 ++++++++++++++++++------------ 1 file changed, 27 insertions(+), 19 deletions(-) diff --git a/frontend/components/signupform.tsx b/frontend/components/signupform.tsx index 2e70519..81234ff 100644 --- a/frontend/components/signupform.tsx +++ b/frontend/components/signupform.tsx @@ -27,28 +27,36 @@ export default function SignupForm() { const onSubmit = async (data: SignupFormData) => { setServerError(null); const toastId = toast.loading("Creating account..."); + let userCredential; try { - const userCredential = await createUserWithEmailAndPassword(auth, data.email, data.password); - - // Update the user's profile with their name - await updateProfile(userCredential.user, { - displayName: data.name - }); - - toast.dismiss(toastId); - toast.success("Account Created!", { - description: "Welcome to InnerHue.", - }); - - router.push("/"); + userCredential = await createUserWithEmailAndPassword( + auth, + data.email, + data.password + ); } catch (error: unknown) { - const message = error instanceof Error ? error.message : "Something went wrong."; - toast.dismiss(toastId); - setServerError(message); - toast.error("Signup failed", { - description: message, - }); + const message = + error instanceof Error ? error.message : "Something went wrong." ; + toast.dismiss(toastId); + setServerError(message) ; + toast.error("Signup failed", { + description: message, + }); + return ;// stop here — don't try updateProfile if account creation failed } + try { + await updateProfile(userCredential.user, { + displayName: data.name, + }); + } catch (profileError) { + console.error("Failed to set display name:", profileError) ; + } + + toast.dismiss(toastId); + toast.success("Account Created!", { + description: "Welcome to InnerHue.", + }); + router.push("/"); }; return (