'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_user') 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 (
{/* 返回按钮 */} 返回首页 {/* Logo */}
秒思

AI 智能审核平台

{/* 登录表单 */}
{error && (
{error}
)}
setEmail(e.target.value)} className="w-full pl-12 pr-4 py-3.5 bg-bg-elevated border border-border-subtle rounded-xl text-text-primary placeholder-text-tertiary focus:outline-none focus:ring-2 focus:ring-accent-indigo focus:border-transparent transition-all" required />
setPassword(e.target.value)} className="w-full pl-12 pr-4 py-3.5 bg-bg-elevated border border-border-subtle rounded-xl text-text-primary placeholder-text-tertiary focus:outline-none focus:ring-2 focus:ring-accent-indigo focus:border-transparent transition-all" required />
{/* Demo 登录 */}

快速体验(Demo 账号)

) } export default function LoginPage() { return (
}>
) }