From 61b0746041528577f16d1f99cb2ac5334c3bba12 Mon Sep 17 00:00:00 2001 From: Pavan Soratur Date: Fri, 18 Oct 2024 20:31:54 -0700 Subject: [PATCH] fix: undefined error --- components/auth/LoginForm.tsx | 8 +++++--- components/auth/RegisterForm.tsx | 11 +++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/components/auth/LoginForm.tsx b/components/auth/LoginForm.tsx index af0ec20..e6b9253 100644 --- a/components/auth/LoginForm.tsx +++ b/components/auth/LoginForm.tsx @@ -34,10 +34,12 @@ export const LoginForm: React.FC = ({ onSubmitAction }) => { const onSubmit = async (data: LoginFormData) => { startTransition(async () => { - const { errorMessage = 'Something went wrong!' } = - await onSubmitAction(data); + const response = await onSubmitAction(data); - if (errorMessage) toast.error(errorMessage); + if (response) { + if (response.errorMessage) toast.error(response.errorMessage); + if (response.successMessage) toast.success(response.successMessage); + } reset(); }); diff --git a/components/auth/RegisterForm.tsx b/components/auth/RegisterForm.tsx index a7cfef9..066434f 100644 --- a/components/auth/RegisterForm.tsx +++ b/components/auth/RegisterForm.tsx @@ -37,13 +37,12 @@ export const RegisterForm: React.FC = ({ const onSubmit = async (data: RegisterFormData) => { startTransition(async () => { - const { - successMessage = 'Successfully registered!', - errorMessage = 'Something went wrong!', - } = await onSubmitAction(data); + const response = await onSubmitAction(data); - if (successMessage) toast.success(successMessage); - if (errorMessage) toast.error(errorMessage); + if (response) { + if (response.errorMessage) toast.error(response.errorMessage); + if (response.successMessage) toast.success(response.successMessage); + } reset(); });