fix: add error handling for admin login page and document admin credentials

- Add URL error parameter handling in login page
- Display appropriate error messages for different error types
- Document default admin credentials
- Provide security guidelines and password management instructions
This commit is contained in:
张翔
2026-03-13 12:31:14 +08:00
parent 5bc8356a37
commit 46e851bc3a
2 changed files with 134 additions and 1 deletions
+23 -1
View File
@@ -1,6 +1,6 @@
'use client';
import { useState, Suspense } from 'react';
import { useState, useEffect, Suspense } from 'react';
import { signIn } from 'next-auth/react';
import { useRouter, useSearchParams } from 'next/navigation';
import { Eye, EyeOff, Mail, Lock, AlertCircle, Loader2 } from 'lucide-react';
@@ -9,6 +9,7 @@ function LoginForm() {
const router = useRouter();
const searchParams = useSearchParams();
const callbackUrl = searchParams.get('callbackUrl') || '/admin';
const urlError = searchParams.get('error');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
@@ -16,6 +17,27 @@ function LoginForm() {
const [error, setError] = useState('');
const [loading, setLoading] = useState(false);
useEffect(() => {
if (urlError) {
switch (urlError) {
case 'Configuration':
setError('认证配置错误,请联系管理员');
break;
case 'AccessDenied':
setError('访问被拒绝,请检查权限');
break;
case 'Verification':
setError('验证失败,请重试');
break;
case 'CredentialsSignin':
setError('邮箱或密码错误');
break;
default:
setError('登录失败,请稍后重试');
}
}
}, [urlError]);
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault();
setError('');