From 1bb1d8140d35ea52db796e38e53c2e11f6f4e36c Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 3 Aug 2023 14:03:06 -0400 Subject: [PATCH] major bug fixed --- hooks/useInitialData.tsx | 5 ++++- pages/register.tsx | 21 ++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/hooks/useInitialData.tsx b/hooks/useInitialData.tsx index b79d5a8..a0bd1c4 100644 --- a/hooks/useInitialData.tsx +++ b/hooks/useInitialData.tsx @@ -13,7 +13,10 @@ export default function useInitialData() { const { setAccount } = useAccountStore(); useEffect(() => { - if (status === "authenticated" && data.user.isSubscriber) { + if ( + status === "authenticated" && + (!process.env.NEXT_PUBLIC_STRIPE_IS_ACTIVE || data.user.isSubscriber) + ) { setCollections(); setTags(); // setLinks(); diff --git a/pages/register.tsx b/pages/register.tsx index d02ddbc..d2236ab 100644 --- a/pages/register.tsx +++ b/pages/register.tsx @@ -3,7 +3,7 @@ import { useState } from "react"; import { toast } from "react-hot-toast"; import SubmitButton from "@/components/SubmitButton"; import { signIn } from "next-auth/react"; -import Image from "next/image"; +import { useRouter } from "next/router"; import CenteredForm from "@/layouts/CenteredForm"; const emailEnabled = process.env.NEXT_PUBLIC_EMAIL_PROVIDER; @@ -18,6 +18,7 @@ type FormData = { export default function Register() { const [submitLoader, setSubmitLoader] = useState(false); + const router = useRouter(); const [form, setForm] = useState({ name: "", @@ -28,7 +29,7 @@ export default function Register() { }); async function registerUser() { - const checkHasEmptyFields = () => { + const checkFields = () => { if (emailEnabled) { return ( form.name !== "" && @@ -46,14 +47,7 @@ export default function Register() { } }; - const sendConfirmation = async () => { - await signIn("email", { - email: form.email, - callbackUrl: "/", - }); - }; - - if (checkHasEmptyFields()) { + if (checkFields()) { if (form.password !== form.passwordConfirmation) return toast.error("Passwords do not match."); else if (form.password.length < 8) @@ -78,7 +72,12 @@ export default function Register() { setSubmitLoader(false); if (response.ok) { - if (form.email) await sendConfirmation(); + if (form.email && emailEnabled) + await signIn("email", { + email: form.email, + callbackUrl: "/", + }); + else if (!emailEnabled) router.push("/login"); toast.success("User Created!"); } else {