fix the order of useMutation so the hook isn't called conditionally

This commit is contained in:
Khalim Conn-Kowlessar 2023-07-13 17:50:15 +01:00
parent 6748d0a625
commit d4252cff16

View file

@ -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";