'use client'; import * as React from 'react'; import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from '@/components/ui/card'; import { toast, Toaster } from 'sonner'; import { showErrorToast } from '@/lib/utils'; export function LoginForm() { const [isLoading, setIsLoading] = useState(false); async function handleLogin(e: React.FormEvent) { e.preventDefault(); setIsLoading(true); const form = e.currentTarget; const formData = new FormData(form); const username = formData.get('username') as string | null; const password = formData.get('password') as string | null; if (!username || !password) { toast.error('Please enter both username and password'); setIsLoading(false); return; } const loginData = { username, password }; try { const response = await fetch('/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(loginData), }); const data = await response.json(); if (response.ok) { toast.success('Login successful!'); // Small delay before redirecting to see the success message setTimeout(() => { window.location.href = '/'; }, 1000); } else { showErrorToast(data.error || 'Login failed. Please try again.', toast); } } catch (error) { showErrorToast(error, toast); } finally { setIsLoading(false); } } return ( <>
Gitea Mirror Logo Gitea Mirror Logo
Gitea Mirror Log in to manage your GitHub to Gitea mirroring

Don't have an account? Contact your administrator.

); }