"use client"; import { useEffect, useRef, useState } from "react"; import type { FormEvent } from "react"; import Image from "next/image"; import { Loader2, LogIn } from "lucide-react"; import { pulseFeedback, revealChildren, runScopedMotion } from "@/lib/ui/motion"; export function AuthLoginPanel({ next, configured, message, missing }: { next: string; configured: boolean; message?: string | null; missing?: string[]; }) { const [username, setUsername] = useState(""); const [password, setPassword] = useState(""); const [submitting, setSubmitting] = useState(false); const [error, setError] = useState(null); const screenRef = useRef(null); const feedbackRef = useRef(null); const hasMissingConfig = !configured && Boolean(missing?.length); useEffect(() => { return runScopedMotion(screenRef, (scope) => revealChildren(scope)); }, []); useEffect(() => { pulseFeedback(feedbackRef.current); }, [error, message, missing?.join(",")]); async function submit(event: FormEvent) { event.preventDefault(); if (!configured || submitting) return; setSubmitting(true); setError(null); try { const payload: Record = { username, password, next }; const response = await fetch("/api/auth/password", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) }); const result = await response.json().catch(() => ({})) as { error?: string; redirectTo?: string }; if (!response.ok) throw new Error(result.error || "登录失败"); window.location.assign(result.redirectTo || next || "/create"); } catch (err) { setError(err instanceof Error ? err.message : String(err)); } finally { setSubmitting(false); } } return (

智念AIGC平台

账户登录

{message || hasMissingConfig || error ? (
{message ?
{message}
: null} {hasMissingConfig ? (
缺少配置:{missing?.join("、")}
) : null} {error ?
{error}
: null}
) : null}
); }