'use client' import { useState } from 'react' export default function LoginPage() { const [username, setUsername] = useState('') const [password, setPassword] = useState('') const [error, setError] = useState('') const [loading, setLoading] = useState(false) const [showLdapForm, setShowLdapForm] = useState(false) const handleSubmit = async (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 } const params = new URLSearchParams(window.location.search) const redirect = params.get('redirect') const dest = (redirect && redirect.startsWith('/')) ? redirect : '/dashboard' window.location.href = dest } catch { setError('网络错误') } finally { setLoading(false) } } function handleSsoLogin() { window.location.href = '/api/auth/login/oidc' } return (
通过 SSO 统一身份认证
> ) : ( <>
> )}