fix(auth): improve login error feedback for better UX
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { useState } from 'react';
|
import { useState, useEffect } from 'react';
|
||||||
import { Form, Input, Button, Card, message, Checkbox } from 'antd';
|
import { Form, Input, Button, Card, message, Checkbox } from 'antd';
|
||||||
import { UserOutlined, LockOutlined, LoginOutlined } from '@ant-design/icons';
|
import { UserOutlined, LockOutlined, LoginOutlined } from '@ant-design/icons';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
@@ -12,6 +12,16 @@ function LoginPage() {
|
|||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const token = localStorage.getItem('authToken');
|
||||||
|
if (token) {
|
||||||
|
const currentUser = authApi.getCurrentUser();
|
||||||
|
if (currentUser) {
|
||||||
|
navigate('/admin/dashboard', { replace: true });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [navigate]);
|
||||||
|
|
||||||
const handleLogin = async (values: { username: string; password: string; remember?: boolean }) => {
|
const handleLogin = async (values: { username: string; password: string; remember?: boolean }) => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user