mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-08 21:03:00 +08:00
32 lines
819 B
TypeScript
32 lines
819 B
TypeScript
import React, { useEffect } from "react";
|
||
import { useDispatch, useSelector } from "react-redux";
|
||
import { useParams } from "react-router";
|
||
import { Redirect } from "react-router-dom";
|
||
import { login, loginSelector } from "src/store/loginSlice";
|
||
|
||
interface AuthParam {
|
||
code: string;
|
||
}
|
||
export function Auth() {
|
||
const { code } = useParams<AuthParam>();
|
||
const dispatch = useDispatch();
|
||
const loginState = useSelector(loginSelector);
|
||
useEffect(() => {
|
||
const loginFun = async () => {
|
||
dispatch(login(code));
|
||
};
|
||
loginFun();
|
||
}, [code, dispatch]);
|
||
return (
|
||
<>
|
||
{loginState.login ? (
|
||
<Redirect to={{ pathname: "/admin" }} />
|
||
) : loginState.failed ? (
|
||
<div>登录失败,请重新获取连接</div>
|
||
) : (
|
||
<div>Logining...</div>
|
||
)}
|
||
</>
|
||
);
|
||
}
|