'use client' import { useState, useEffect, Suspense } from 'react' import { useRouter, useSearchParams } from 'next/navigation' import { useAuth } from '@/contexts/AuthContext' import { ShieldCheck, AlertCircle, ArrowLeft, Mail, Lock } from 'lucide-react' import Link from 'next/link' function LoginForm() { const router = useRouter() const searchParams = useSearchParams() const { login } = useAuth() const [email, setEmail] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [isLoading, setIsLoading] = useState(false) const [autoLoginAttempted, setAutoLoginAttempted] = useState(false) // 如果 URL 有 role 参数,自动触发 demo 登录 const roleFromUrl = searchParams.get('role') as 'creator' | 'agency' | 'brand' | null const handleDemoLogin = async (role: 'creator' | 'agency' | 'brand') => { const emailMap = { creator: 'creator@demo.com', agency: 'agency@demo.com', brand: 'brand@demo.com', } const demoEmail = emailMap[role] setEmail(demoEmail) setPassword('demo123') setError('') setIsLoading(true) const result = await login({ email: demoEmail, password: 'demo123' }) if (result.success) { switch (role) { case 'creator': router.push('/creator') break case 'agency': router.push('/agency') break case 'brand': router.push('/brand') break } } else { setError(result.error || '登录失败') } setIsLoading(false) } useEffect(() => { if (roleFromUrl && !isLoading && !autoLoginAttempted) { setAutoLoginAttempted(true) handleDemoLogin(roleFromUrl) } }, [roleFromUrl]) const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setError('') setIsLoading(true) const result = await login({ email, password }) if (result.success) { const stored = localStorage.getItem('miaosi_auth') if (stored) { const user = JSON.parse(stored) switch (user.role) { case 'creator': router.push('/creator') break case 'agency': router.push('/agency') break case 'brand': router.push('/brand') break default: router.push('/') } } } else { setError(result.error || '登录失败') } setIsLoading(false) } return (
AI 智能审核平台
快速体验(Demo 账号)