import { useState } from "react"; import { Link, useLocation } from "wouter"; import { useAuth } from "@/hooks/useAuth"; import { useTheme } from "@/context/ThemeContext"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Checkbox } from "@/components/ui/checkbox"; import { Badge } from "@/components/ui/badge"; import { useToast } from "@/hooks/use-toast"; import { Mic, Moon, Sun, Loader2, AlertCircle, CheckCircle2 } from "lucide-react"; import { cn } from "@/lib/utils"; export default function LoginPage() { const [location, setLocation] = useLocation(); const { login, register, user } = useAuth(); const { theme, toggleTheme } = useTheme(); const { toast } = useToast(); const isRegisterMode = location === "/register"; const [formData, setFormData] = useState({ email: "", password: "", confirmPassword: "", username: "", firstName: "", lastName: "", role: "standard", rememberMe: false, }); const [isSubmitting, setIsSubmitting] = useState(false); const [error, setError] = useState(""); // Redirect if already authenticated if (user) { setLocation("/dashboard"); return null; } const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(""); setIsSubmitting(true); try { if (isRegisterMode) { if (formData.password !== formData.confirmPassword) { setError("Passwords do not match"); return; } await register({ username: formData.username, email: formData.email, password: formData.password, confirmPassword: formData.confirmPassword, firstName: formData.firstName, lastName: formData.lastName, role: formData.role, }); toast({ title: "Account created!", description: "You have successfully registered. Please sign in.", }); setLocation("/login"); } else { await login(formData.email, formData.password); toast({ title: "Welcome back!", description: "You have successfully signed in.", }); setLocation("/dashboard"); } } catch (error: any) { console.error("Auth error:", error); setError(error.message || `Failed to ${isRegisterMode ? 'register' : 'sign in'}. Please try again.`); } finally { setIsSubmitting(false); } }; const handleInputChange = (field: string, value: string | boolean) => { setFormData(prev => ({ ...prev, [field]: value })); if (error) setError(""); // Clear error on input change }; return (
{/* Header with Logo and Theme Toggle */}
TaskFin
{/* Main Login Card */} {isRegisterMode ? "Create Account" : "Welcome Back"} {isRegisterMode ? "Join TaskFin to manage your tasks and finances with AI" : "Sign in to your TaskFin account to access your voice-powered productivity tools" } {/* Features Badge */}
Local Voice AI Complete Privacy
{/* Error Alert */} {error && ( {error} )} {/* Registration Fields */} {isRegisterMode && ( <>
handleInputChange("firstName", e.target.value)} disabled={isSubmitting} required />
handleInputChange("lastName", e.target.value)} disabled={isSubmitting} required />
handleInputChange("username", e.target.value)} disabled={isSubmitting} required />
)} {/* Email Field */}
handleInputChange("email", e.target.value)} disabled={isSubmitting} required className="focus-ring" />
{/* Password Field */}
handleInputChange("password", e.target.value)} disabled={isSubmitting} required className="focus-ring" />
{/* Confirm Password Field - Registration Only */} {isRegisterMode && (
handleInputChange("confirmPassword", e.target.value)} disabled={isSubmitting} required className="focus-ring" />
)} {/* Remember Me & Forgot Password */}
handleInputChange("rememberMe", !!checked)} disabled={isSubmitting} />
{/* Submit Button */} {/* Switch between Login/Register */}
{isRegisterMode ? "Already have an account? " : "Don't have an account? "} {isRegisterMode ? "Sign in" : "Create one"}
{/* Divider */}
Or
{/* Register Link */}
Don't have an account?{" "}
{/* Demo Credentials (for development) */}

Demo Accounts:

Standard: user@taskfin.local / password

Pro: pro@taskfin.local / password

Admin: admin@taskfin.local / password

{/* Features Overview */}
Local STT/TTS Processing
Zero Cloud Dependencies
Complete Data Privacy
); }