diff --git a/src/client/error.d.ts b/src/client/error.d.ts new file mode 100644 index 0000000..832fa3e --- /dev/null +++ b/src/client/error.d.ts @@ -0,0 +1,4 @@ +export interface ErrorResponse extends Error { + status: number + error: { msg: string } +} diff --git a/src/pages/Login/index.tsx b/src/pages/Login/index.tsx index 235b63e..bbdadca 100644 --- a/src/pages/Login/index.tsx +++ b/src/pages/Login/index.tsx @@ -1,8 +1,9 @@ import { useRequest } from 'ahooks' +import type { ErrorResponse } from 'client/error' import PageContainer from 'components/PageContainer' import { useAuth } from 'hooks/useAuth' import { useState } from 'react' -import { Col, Row } from 'react-bootstrap' +import { Alert, Col, Row } from 'react-bootstrap' import Button from 'react-bootstrap/Button' import Form from 'react-bootstrap/Form' import { Navigate, useSearchParams } from 'react-router-dom' @@ -11,6 +12,7 @@ import Backend from 'utils/service' const LoginForm: React.FC = () => { const { user } = useAuth() + const [error, setError] = useState('') const [searchParams] = useSearchParams() const [username, setUsername] = useState('demo') const [password, setPassword] = useState('123456') @@ -33,6 +35,9 @@ const LoginForm: React.FC = () => { if (res.data.redirect_url) { window.location.href = res.data.redirect_url } + }, + onError: err => { + setError((err as ErrorResponse).error.msg) } } ) @@ -49,6 +54,7 @@ const LoginForm: React.FC = () => {