From d1e1ccdc37854fb5d92a519338fb00d6552aa385 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Wed, 6 Aug 2025 00:05:52 +0000 Subject: [PATCH] Update Login component logic to use Supabase cgen-38f9359cd6e848a49c0dfa0a48771011 --- client/pages/Login.tsx | 50 +++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/client/pages/Login.tsx b/client/pages/Login.tsx index 14dca197..83886a3e 100644 --- a/client/pages/Login.tsx +++ b/client/pages/Login.tsx @@ -28,28 +28,58 @@ import { export default function Login() { const [isLoading, setIsLoading] = useState(false); + const [isSignUp, setIsSignUp] = useState(false); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); + const [fullName, setFullName] = useState(""); const navigate = useNavigate(); + const { signIn, signUp, user, loading } = useAuth(); - const handleLogin = async (e: React.FormEvent) => { + // Redirect if already logged in + useEffect(() => { + if (user && !loading) { + navigate("/dashboard"); + } + }, [user, loading, navigate]); + + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); - // Simulate login process - setTimeout(() => { + try { + if (isSignUp) { + await signUp(email, password, { + id: "", // Will be set by Supabase + full_name: fullName, + user_type: "game_developer", // Default, can be changed in onboarding + username: email.split("@")[0], // Generate username from email + }); + aethexToast.success({ + title: "Account created!", + description: "Please check your email to verify your account, then sign in." + }); + setIsSignUp(false); + } else { + await signIn(email, password); + navigate("/dashboard"); + } + } catch (error: any) { + console.error("Authentication error:", error); + } finally { setIsLoading(false); - navigate("/dashboard"); - }, 2000); + } }; - const handleSocialLogin = (provider: string) => { + const handleSocialLogin = async (provider: string) => { setIsLoading(true); - // Simulate social login - setTimeout(() => { + try { + aethexToast.info({ + title: "Social login", + description: `${provider} login will be implemented in your Supabase setup` + }); + } finally { setIsLoading(false); - navigate("/dashboard"); - }, 1500); + } }; if (isLoading) {