fix: tweak UX

This commit is contained in:
Tristan Yang
2023-02-28 20:04:53 +08:00
parent 4eff75af64
commit 270cac5a44
6 changed files with 47 additions and 45 deletions
+4 -3
View File
@@ -4,6 +4,7 @@ import { GuestRoutes } from "../../app/config";
import { useGetInitializedQuery } from "../../app/services/auth";
import { useGetLoginConfigQuery } from "../../app/services/server";
import { useAppSelector } from "../../app/store";
import Loading from "./Loading";
interface Props {
children: ReactElement;
@@ -14,15 +15,15 @@ const GuestAllows = GuestRoutes.map((path) => {
});
const RequireAuth: FC<Props> = ({ children, redirectTo = "/login" }) => {
const location = useLocation();
const matchs = matchRoutes(GuestAllows, location);
const allowGuest = matchs ? !!matchs[0].pathname : false;
const matches = matchRoutes(GuestAllows, location);
const allowGuest = matches ? !!matches[0].pathname : false;
const { data: loginConfig, isSuccess: loginConfigSuccess } = useGetLoginConfigQuery();
const { isSuccess: checkInitialSuccess } = useGetInitializedQuery();
const { token, guest, initialized } = useAppSelector((store) => store.authData);
// console.log("auth route", { checkInitialSuccess, loginConfigSuccess, initialized, guest: loginConfig?.guest, token, allowGuest, guest });
// 初始化和login配置检查
if (!checkInitialSuccess || !loginConfigSuccess) return null;
if (!checkInitialSuccess || !loginConfigSuccess) return <Loading fullscreen={true} />;
// 未初始化 则先走setup 流程
if (!initialized) return <Navigate to={`/onboarding`} replace />;
// 开启guest 并且没token 而且是允许guest访问的路由 则先去过渡页登录