Feat: Add Passport + JWT
增加 Passport 和 JWT 验证支持(目前为假验证)前端登录页面,部分页面内容和样式优化
This commit is contained in:
+1
-2
@@ -18,7 +18,7 @@ const apiMap: Record<string, string> = {
|
||||
|
||||
function Index() {
|
||||
|
||||
const { data: stat } = useRequest(() => getStat());
|
||||
const { data: stat } = useRequest(getStat);
|
||||
|
||||
return (
|
||||
<main>
|
||||
@@ -87,7 +87,6 @@ function Index() {
|
||||
<About />
|
||||
</article>
|
||||
</main>
|
||||
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
// React
|
||||
import React from "react";
|
||||
import { useNavigate } from "react-router-dom";
|
||||
import { useRequest } from "ahooks";
|
||||
import useStat from "@/hooks/useStat";
|
||||
import useGlobalContext from "@/hooks/useGlobalContext";
|
||||
|
||||
|
||||
// UI
|
||||
import ArticleHead from "@/components/Layout/ArticleHead";
|
||||
|
||||
|
||||
// Tool
|
||||
import loginRequest from "../server/api/auth/login";
|
||||
|
||||
|
||||
// Interface
|
||||
import { MouseEvent, ChangeEvent } from "react";
|
||||
|
||||
|
||||
// Components
|
||||
function Login() {
|
||||
const navigate = useNavigate();
|
||||
const { globalData, setGlobalData } = useGlobalContext();
|
||||
const { loading, run } = useRequest(
|
||||
(params) => loginRequest({
|
||||
query: params
|
||||
}),
|
||||
{
|
||||
manual: true,
|
||||
onSuccess: (data) => {
|
||||
console.log(data);
|
||||
|
||||
setGlobalData({
|
||||
type: "profile",
|
||||
value: data.profile
|
||||
});
|
||||
|
||||
navigate("/")
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const [input, setInput] = useStat({
|
||||
username: "",
|
||||
password: ""
|
||||
});
|
||||
|
||||
const onSubmit = (ev: MouseEvent<HTMLButtonElement>) => {
|
||||
ev.preventDefault();
|
||||
|
||||
run(input);
|
||||
|
||||
console.log("ok");
|
||||
}
|
||||
|
||||
const onInputChange = (ev: ChangeEvent<HTMLInputElement>) => {
|
||||
setInput({ [ev.target.name]: ev.target.value });
|
||||
}
|
||||
|
||||
return (
|
||||
<main>
|
||||
<ArticleHead title="登录" desc="目前来说,登录是没有用的" />
|
||||
<form>
|
||||
<fieldset>
|
||||
<label>
|
||||
<input type="text" name="username" placeholder="用户名"
|
||||
value={input.username} onChange={onInputChange}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
<input type="password" name="password" placeholder="密码"
|
||||
value={input.password} onChange={onInputChange}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
<button className="btn green" onClick={onSubmit}>
|
||||
{
|
||||
loading ? <i className="fa fa-spinner fa-spin"></i> : "登录"
|
||||
}
|
||||
</button>
|
||||
</label>
|
||||
</fieldset>
|
||||
</form>
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
export default Login;
|
||||
Reference in New Issue
Block a user