From 18a096b7b41b4c71628bb9ffc20d9e3f9b841fc5 Mon Sep 17 00:00:00 2001 From: Vineeth Voruganti <13438633+VVoruganti@users.noreply.github.com> Date: Mon, 2 Sep 2024 11:36:05 -0400 Subject: [PATCH] Middleware matcher --- www/app/auth/page.tsx | 34 ++++------ www/app/page.tsx | 7 ++- www/components/auth/reset.tsx | 1 + www/components/auth/signIn.tsx | 1 + www/components/auth/signUp.tsx | 111 +++++++++++++++------------------ www/middleware.ts | 1 + www/next.config.mjs | 41 +++--------- 7 files changed, 81 insertions(+), 115 deletions(-) diff --git a/www/app/auth/page.tsx b/www/app/auth/page.tsx index ce41686..b8509ca 100644 --- a/www/app/auth/page.tsx +++ b/www/app/auth/page.tsx @@ -1,6 +1,6 @@ 'use client' import { createClient } from '@/utils/supabase/client' -import { useEffect, useState } from "react"; +import { useEffect, useState, Suspense } from "react"; import { redirect } from "next/navigation"; import Image from "next/image"; @@ -23,19 +23,10 @@ export default function Auth() { } }) - const { data: subscription } = supabase.auth.onAuthStateChange(async (event, session) => { - if (event != "INITIAL_SESSION") { - console.log(event) - } - if (event == "PASSWORD_RECOVERY") { - redirect("/auth/reset") - } - - }) }, [supabase]) return ( -
+
diff --git a/www/app/page.tsx b/www/app/page.tsx index ad46a4b..ee09d9c 100644 --- a/www/app/page.tsx +++ b/www/app/page.tsx @@ -2,10 +2,12 @@ import Image from "next/image"; import useSWR from "swr"; +import dynamic from "next/dynamic"; + import banner from "@/public/bloom2x1.svg"; import darkBanner from "@/public/bloom2x1dark.svg"; import MessageBox from "@/components/messagebox"; -import Thoughts from "@/components/thoughts"; +// import Thoughts from "@/components/thoughts"; import Sidebar from "@/components/sidebar"; import MarkdownWrapper from "@/components/markdownWrapper"; import { DarkModeSwitch } from "react-toggle-dark-mode"; @@ -19,11 +21,12 @@ import { usePostHog } from "posthog-js/react"; import { API } from "@/utils/api"; import { createClient } from "@/utils/supabase/client"; +const Thoughts = dynamic(() => import("@/components/thoughts")); + const URL = process.env.NEXT_PUBLIC_API_URL; export default function Home() { const [userId, setUserId] = useState(); - // const [session, setSession] = useState(null); const [isThoughtsOpen, setIsThoughtsOpen] = useState(false); const [isSidebarOpen, setIsSidebarOpen] = useState(false); diff --git a/www/components/auth/reset.tsx b/www/components/auth/reset.tsx index 759d49d..25c4245 100644 --- a/www/components/auth/reset.tsx +++ b/www/components/auth/reset.tsx @@ -1,3 +1,4 @@ +'use client'; import { useState, useEffect } from "react"; import { createClient } from "@/utils/supabase/client"; import { useRouter } from "next/navigation"; diff --git a/www/components/auth/signIn.tsx b/www/components/auth/signIn.tsx index c079af1..985fb3d 100644 --- a/www/components/auth/signIn.tsx +++ b/www/components/auth/signIn.tsx @@ -1,3 +1,4 @@ +'use client'; import { useState, useRef } from "react"; import Swal from 'sweetalert2' diff --git a/www/components/auth/signUp.tsx b/www/components/auth/signUp.tsx index 8a0232d..aa68b7a 100644 --- a/www/components/auth/signUp.tsx +++ b/www/components/auth/signUp.tsx @@ -1,4 +1,5 @@ -import { useState } from "react"; +'use client'; +import { useState, useRef } from "react"; import { useRouter } from "next/navigation"; import Swal from 'sweetalert2' @@ -10,65 +11,58 @@ export default function SignUp(props: any) { const [passwordConfirmation, setPasswordConfirmation] = useState(''); const [opt, setOpt] = useState(true) const [age, setAge] = useState(false) - const router = useRouter(); - // const supabase = createClientComponentClient() - - // const handleSignUp = async (e: any) => { - // e.preventDefault(); - // if (!age) { - // await Swal.fire({ - // title: "Age Verification Required", - // icon: 'error', - // text: 'Please confirm that you are 13 years or older', - // }) - // return - // } - // if (password !== passwordConfirmation) { - // await Swal.fire({ - // title: "Passwords don't match", - // icon: 'error', - // text: 'Re-confirm you password and try again', - // }) - // return - // } - // if (password.length < 6) { - // await Swal.fire({ - // title: "Insufficient Password", - // icon: 'error', - // text: 'Make sure the password is atleast 6 characters long', - // }) - // return - // } - // const { error } = await supabase.auth.signUp( - // { - // email, - // password, - // options: { - // emailRedirectTo: `${location.origin}/`, - // data: { - // dataOptIn: opt, - // ageVerification: age - // } - // } - // }); - // if (error) { - // Swal.fire({ - // title: "Something went wrong", - // icon: "error", - // text: "Please try again and make sure the password is atleast 6 characters long", - // }) - // console.error(error); - // } else { - // Swal.fire({ - // title: "Success", - // icon: "success", - // text: "Please check your email for a verification link" - // }) - // } - // }; + const formRef = useRef(null); + + const handleSignUp = async (e: React.FormEvent) => { + e.preventDefault(); + if (!formRef.current) return; + const formData = new FormData(formRef.current); + if (!age) { + await Swal.fire({ + title: "Age Verification Required", + icon: 'error', + text: 'Please confirm that you are 13 years or older', + }) + return + } + console.log(password, passwordConfirmation) + if (password !== passwordConfirmation) { + await Swal.fire({ + title: "Passwords don't match", + icon: 'error', + text: 'Re-confirm you password and try again', + }) + return + } + if (password.length < 6) { + await Swal.fire({ + title: "Insufficient Password", + icon: 'error', + text: 'Make sure the password is atleast 6 characters long', + }) + return + } + + const error = await handler(formData); + if (error) { + Swal.fire({ + title: "Something went wrong", + icon: "error", + text: "Please try again and make sure the password is atleast 6 characters long", + }) + console.error(error); + } else { + Swal.fire({ + title: "Success", + icon: "success", + text: "Please check your email for a verification link" + }) + } + } + return ( -
+