From 7d36510a9b9dc41537c539bd2b57efa38ef7d743 Mon Sep 17 00:00:00 2001 From: Alibek Date: Wed, 13 Mar 2024 16:48:13 +0600 Subject: [PATCH] fixed bug with sign-in --- src/app/[locale]/profile/page.tsx | 14 +++++++++++--- src/features/BreadCrumbs/BreadCrumbs.tsx | 2 ++ src/shared/config/authConfig.ts | 14 +++++--------- .../confirm-code/confirm-code.tsx | 2 +- .../ForgotPasswordForm/send-email/send-email.tsx | 2 +- src/widgets/forms/SignInForm/SignInForm.tsx | 2 ++ 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/app/[locale]/profile/page.tsx b/src/app/[locale]/profile/page.tsx index db4d387..a4d9918 100644 --- a/src/app/[locale]/profile/page.tsx +++ b/src/app/[locale]/profile/page.tsx @@ -1,5 +1,13 @@ -const page = () => { - return
page
; +"use client"; +import { useRouter } from "@/shared/config/navigation"; +import { useEffect } from "react"; + +const Profile = () => { + const router = useRouter(); + useEffect(() => { + router.push("/profile/personal"); + }, []); + return <>; }; -export default page; +export default Profile; diff --git a/src/features/BreadCrumbs/BreadCrumbs.tsx b/src/features/BreadCrumbs/BreadCrumbs.tsx index 6026d07..d6ca14b 100644 --- a/src/features/BreadCrumbs/BreadCrumbs.tsx +++ b/src/features/BreadCrumbs/BreadCrumbs.tsx @@ -40,6 +40,8 @@ const BreadCrumbs: React.FC = ({ )} {routes.map((route, i, array) => { + if (routes.length === 1 && routes[0] === "profile") + return null; if (parseInt(route)) { if (routes[0] === "news") { return {query}; diff --git a/src/shared/config/authConfig.ts b/src/shared/config/authConfig.ts index f4ad5f4..a764a8e 100644 --- a/src/shared/config/authConfig.ts +++ b/src/shared/config/authConfig.ts @@ -70,12 +70,12 @@ export const authConfig: AuthOptions = { const res = await apiInstance.post("/users/login/", data); - if (![200, 201].includes(res.status)) { - return null; + if ([200, 201].includes(res.status)) { + const user = res.data; + return user; } - const user = res.data; - return user; + return null; }, }), GoogleProvider({ @@ -90,11 +90,7 @@ export const authConfig: AuthOptions = { strategy: "jwt", }, callbacks: { - async signIn({ account, profile, user }) { - if (!profile?.email) { - throw new Error("No Profile"); - } - + async signIn({ account, user }) { if (account?.provider === "google") { const data = { auth_token: account?.id_token, diff --git a/src/widgets/forms/ForgotPasswordForm/confirm-code/confirm-code.tsx b/src/widgets/forms/ForgotPasswordForm/confirm-code/confirm-code.tsx index 0c8259a..9a34346 100644 --- a/src/widgets/forms/ForgotPasswordForm/confirm-code/confirm-code.tsx +++ b/src/widgets/forms/ForgotPasswordForm/confirm-code/confirm-code.tsx @@ -44,9 +44,9 @@ const ConfirmCode: React.FC = ({ ); router.push("/sign-in/reset-code"); } + setLoader(false); } catch (error) { setError("An error ocured"); - } finally { setLoader(false); } }; diff --git a/src/widgets/forms/ForgotPasswordForm/send-email/send-email.tsx b/src/widgets/forms/ForgotPasswordForm/send-email/send-email.tsx index 2eb1d2b..774a825 100644 --- a/src/widgets/forms/ForgotPasswordForm/send-email/send-email.tsx +++ b/src/widgets/forms/ForgotPasswordForm/send-email/send-email.tsx @@ -57,7 +57,7 @@ const SendEmail: React.FC = ({
{ setLoader(false); + console.log(res); + if (res?.ok && !res.error) { router.push("/profile/personal"); } else if (res?.status.toString().slice(0, 1) === "4") {