From d4252cff16622fcbc5cdd08d6d6fd6c86c20ff02 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Thu, 13 Jul 2023 17:50:15 +0100 Subject: [PATCH] fix the order of useMutation so the hook isn't called conditionally --- src/app/components/home/ModalSubmit.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/app/components/home/ModalSubmit.tsx b/src/app/components/home/ModalSubmit.tsx index eac359b..d3d7258 100644 --- a/src/app/components/home/ModalSubmit.tsx +++ b/src/app/components/home/ModalSubmit.tsx @@ -66,12 +66,6 @@ const ModalSubmit = ({ // This is a client component so we can access the session directly const session = useSession(); - if (!session.data) { - // The user is not logged in, redirect them to sign in - router.push("/"); - return null; - } - const { mutate, isLoading } = useMutation(createPortfolio, { onSuccess: (data) => { router.push(`/portfolio/${data.id}`); @@ -82,6 +76,12 @@ const ModalSubmit = ({ }, }); + if (!session.data) { + // The user is not logged in, redirect them to sign in + router.push("/"); + return null; + } + const handleSubmit = () => { const userId = session.data.user.dbId; const status = "scoping";