Redirect login success to admin

This commit is contained in:
rayd1o
2026-04-09 00:37:02 +08:00
parent ef65acd49c
commit 34d94a6b6b

View File

@@ -1,10 +1,12 @@
import { useState } from 'react'
import { Input, Button, Form, message } from 'antd'
import { UserOutlined, LockOutlined } from '@ant-design/icons'
import { useNavigate } from 'react-router-dom'
import { useAuthStore } from '../../stores/auth'
function Login() {
const [loading, setLoading] = useState(false)
const navigate = useNavigate()
const { login } = useAuthStore()
const onFinish = async (values: { username: string; password: string }) => {
@@ -12,6 +14,7 @@ function Login() {
try {
await login(values.username, values.password)
message.success('登录成功')
navigate('/admin', { replace: true })
} catch (error: unknown) {
const err = error as { response?: { data?: { detail?: string } } }
message.error(err.response?.data?.detail || '登录失败')