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