// pages/index.tsx "use client"; import Button from "@/components/Button"; import Input from "@/components/Input"; import InlineLink from "@/components/InlineLink"; import Image from "next/image"; import { useEffect, useState } from "react"; import PasswordInput from "@/components/auth/PasswordInput"; import ErrorBanner from "@/components/auth/ErrorBanner"; import { login } from "../actions"; import { createClient } from "@/utils/supabase/client"; import { useRouter } from "next/navigation"; export default function Page() { const router = useRouter(); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const [emailError, setEmailError] = useState(""); const [passwordError, setPasswordError] = useState(""); const [loginError, setLoginError] = useState(""); const [isLoading, setIsLoading] = useState(false); useEffect(() => { const supabase = createClient(); async function checkUser() { const { data } = await supabase.auth.getUser(); if (data.user) { router.push("/home"); } } checkUser(); }, [router]); const handleEmailChange = (event: React.ChangeEvent) => { setEmail(event.currentTarget.value); }; const handlePasswordChange = ( event: React.ChangeEvent ) => { setPassword(event.currentTarget.value); }; const handleClick = async (event: React.MouseEvent) => { event.preventDefault(); const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; if (email.trim().length === 0) { setEmailError("Please enter your email."); return; } if (!emailRegex.test(email)) { setEmailError("Please enter a valid email address."); return; } setEmailError(""); if (password.trim().length === 0) { setPasswordError("Please enter your password."); return; } setPasswordError(""); setIsLoading(true); const error = await login(email, password); setIsLoading(false); if (error) { setLoginError(error); } }; return ( <> Compass Center logo.

Login

{emailError && }
{passwordError && }
Forgot password?
{loginError && } ); }