'use client' import { useState, Suspense } from 'react' import { useSearchParams } from 'next/navigation' function LoginPageContent() { const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [loading, setLoading] = useState(false) const [showLdapForm, setShowLdapForm] = useState(false) const searchParams = useSearchParams() const isLocalMode = searchParams.get('method') === 'local' async function handleSubmit(e: React.FormEvent) { e.preventDefault(); setError(''); setLoading(true) try { const res = await fetch('/api/auth/login', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password }), }) const data = await res.json() if (!res.ok) { setError(data.error || '登录失败'); return } window.location.href = '/' } catch { setError('网络错误') } finally { setLoading(false) } } function handleSsoLogin() { fetch('/api/auth/login/oidc').then(res => { if (res.status === 200) { return res.json().then(data => { if (data.conflict) { window.location.href = '/' } else { setError(data.error || '登录失败') } }) } window.location.href = res.url || '/api/auth/login/oidc' }).catch(() => { window.location.href = '/api/auth/login/oidc' }) } const showLocalForm = isLocalMode || showLdapForm return (

统一门户

{error &&
{error}
} {!showLocalForm ? ( <>

通过 SSO 统一身份认证

) : ( <>
setUsername(e.target.value)} placeholder="请输入用户名" className="w-full px-3 py-2 rounded-lg border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-800 text-slate-900 dark:text-white placeholder:text-slate-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" required />
setPassword(e.target.value)} placeholder="请输入密码" className="w-full px-3 py-2 rounded-lg border border-slate-300 dark:border-slate-600 bg-white dark:bg-slate-800 text-slate-900 dark:text-white placeholder:text-slate-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent" required />
{!isLocalMode && (

)} )}
) } export default function LoginPage() { return ( 加载中...}> ) }