import { useState, useEffect } from "react"; import { useNavigate, Link } from "react-router-dom"; import { useAuth } from "@/contexts/AuthContext"; import { useAethexToast } from "@/hooks/use-aethex-toast"; import Layout from "@/components/Layout"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Badge } from "@/components/ui/badge"; import LoadingScreen from "@/components/LoadingScreen"; import { LogIn, ArrowRight, Shield, Sparkles, Github, Mail, Lock, User, } from "lucide-react"; 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, signInWithOAuth, user, loading } = useAuth(); // Redirect if already logged in useEffect(() => { if (user && !loading) { navigate("/dashboard"); } }, [user, loading, navigate]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setIsLoading(true); 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); } }; const handleSocialLogin = async (provider: "github" | "google") => { setIsLoading(true); try { await signInWithOAuth(provider); } catch (error: any) { console.error(`${provider} authentication error:`, error); } finally { setIsLoading(false); } }; if (isLoading) { return ( ); } return (
{/* Floating particles effect */}
{[...Array(20)].map((_, i) => (
))}
{isSignUp ? "Create Account" : "Welcome Back"} {isSignUp ? "Create your AeThex account to get started" : "Sign in to your AeThex account to access the dashboard"}
Secure Login
{/* Social Login Buttons */}
Or continue with email
{/* Email/Password Form */}
{isSignUp && (
setFullName(e.target.value)} placeholder="Enter your full name" className="pl-10 bg-background/50 border-border/50 focus:border-aethex-400" required={isSignUp} />
)}
setEmail(e.target.value)} placeholder="Enter your email" className="pl-10 bg-background/50 border-border/50 focus:border-aethex-400" required />
setPassword(e.target.value)} placeholder={ isSignUp ? "Create a password" : "Enter your password" } className="pl-10 bg-background/50 border-border/50 focus:border-aethex-400" required minLength={isSignUp ? 6 : undefined} />
{isSignUp && (

Password must be at least 6 characters long

)}
{!isSignUp && (
)}

{isSignUp ? "Already have an account?" : "Don't have an account?"}{" "}

{/* Security Notice */}

🔒 Your data is protected with enterprise-grade security

); }