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:
@@ -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('');
|
||||
|
||||
Reference in New Issue
Block a user