"use client" import React, { useState } from "react" 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 { useAuth } from "@/lib/auth-context" import { Mail, Lock, LogIn, AlertCircle } from "lucide-react" // Defines props for the LoginForm component interface LoginFormProps { onSwitchToRegister: () => void // Function to switch to the registration form } // LoginForm component for user authentication export function LoginForm({ onSwitchToRegister }: LoginFormProps) { // Access authentication context for login functionality const { login } = useAuth() // State variables for form inputs and UI feedback const [email, setEmail] = useState("") const [password, setPassword] = useState("") const [error, setError] = useState("") const [isLoading, setIsLoading] = useState(false) // Handles form submission for user login const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() // Prevent default form submission behavior setError("") // Clear previous errors setIsLoading(true) // Show loading indicator // Attempt to log in the user const success = await login(email, password) if (!success) { setError("Ungültige E-Mail oder Passwort") // Set error message on failure } setIsLoading(false) // Hide loading indicator } return ( Willkommen zurück Bitte melden Sie sich an
{/* Display error message if present */} {error && (
{error}
)} {/* Email input field */}
setEmail(e.target.value)} className="pl-10" required />
{/* Password input field */}
setPassword(e.target.value)} className="pl-10" required />
{/* Informational message for users */}

Hinweis:

Nutzen Sie Ihre registrierten Zugangsdaten.

{/* Submit button with loading state */} {/* Link to switch to registration form */}

{"Noch kein Konto? "}

) }