diff --git a/apps/app/pages/index.tsx b/apps/app/pages/index.tsx index ab2633241..abe317415 100644 --- a/apps/app/pages/index.tsx +++ b/apps/app/pages/index.tsx @@ -46,14 +46,12 @@ const HomePage: NextPage = () => { } else { throw Error("Cant find credentials"); } - } catch (error: any) { - console.log(error); + } catch (err: any) { setToastAlert({ title: "Error signing in!", type: "error", message: - error?.error || - "Something went wrong. Please try again later or contact the support team.", + err?.error || "Something went wrong. Please try again later or contact the support team.", }); } }; @@ -71,13 +69,12 @@ const HomePage: NextPage = () => { } else { throw Error("Cant find credentials"); } - } catch (error: any) { + } catch (err: any) { setToastAlert({ title: "Error signing in!", type: "error", message: - error?.error || - "Something went wrong. Please try again later or contact the support team.", + err?.error || "Something went wrong. Please try again later or contact the support team.", }); } }; @@ -88,22 +85,23 @@ const HomePage: NextPage = () => { .then((response) => { try { if (response) mutateUser(); - } catch (error: any) { - console.log(error); + } catch (err: any) { setToastAlert({ - title: "Error signing in!", type: "error", + title: "Error!", message: - error?.error || + err?.error || "Something went wrong. Please try again later or contact the support team.", }); } }) - .catch(() => + .catch((err) => setToastAlert({ - title: "Oops!", type: "error", - message: "Enter the correct email address and password to sign in", + title: "Error!", + message: + err?.error || + "Something went wrong. Please try again later or contact the support team.", }) ); }; @@ -111,14 +109,12 @@ const HomePage: NextPage = () => { const handleEmailCodeSignIn = async (response: any) => { try { if (response) mutateUser(); - } catch (error: any) { - console.log(error); + } catch (err: any) { setToastAlert({ - title: "Error signing in!", type: "error", + title: "Error!", message: - error?.error || - "Something went wrong. Please try again later or contact the support team.", + err?.error || "Something went wrong. Please try again later or contact the support team.", }); } }; diff --git a/apps/app/pages/reset-password.tsx b/apps/app/pages/reset-password.tsx index 86ab556b1..82ee32114 100644 --- a/apps/app/pages/reset-password.tsx +++ b/apps/app/pages/reset-password.tsx @@ -63,11 +63,13 @@ const ResetPasswordPage: NextPage = () => { }); router.push("/"); }) - .catch(() => + .catch((err) => setToastAlert({ type: "error", title: "Error!", - message: "Something went wrong. Please try again.", + message: + err?.error || + "Something went wrong. Please try again later or contact the support team.", }) ); }; diff --git a/apps/app/pages/sign-up.tsx b/apps/app/pages/sign-up.tsx index eeffb53bd..2c86d96ff 100644 --- a/apps/app/pages/sign-up.tsx +++ b/apps/app/pages/sign-up.tsx @@ -47,20 +47,15 @@ const SignUp: NextPage = () => { if (response) await mutateUser(); router.push("/"); }) - .catch((err) => { - if (err.status === 400) - setToastAlert({ - type: "error", - title: "Error!", - message: "An user already exists with this Email ID.", - }); - else - setToastAlert({ - type: "error", - title: "Error!", - message: "Something went wrong. Please try again later or contact the support team.", - }); - }); + .catch((err) => + setToastAlert({ + type: "error", + title: "Error!", + message: + err?.error || + "Something went wrong. Please try again later or contact the support team.", + }) + ); }; return ( diff --git a/apps/app/services/authentication.service.ts b/apps/app/services/authentication.service.ts index f0d19da24..86f55e329 100644 --- a/apps/app/services/authentication.service.ts +++ b/apps/app/services/authentication.service.ts @@ -28,7 +28,7 @@ class AuthService extends APIService { return response?.data; }) .catch((error) => { - throw error?.response; + throw error?.response?.data; }); } @@ -51,6 +51,7 @@ class AuthService extends APIService { throw error?.response?.data; }); } + async magicSignIn(data: any) { const response = await this.post("/api/magic-sign-in/", data, { headers: {} }); if (response?.status === 200) {