fix: debug the loading problem
This commit is contained in:
@@ -18,12 +18,28 @@ const RequireAuth: FC<Props> = ({ children, redirectTo = "/login" }) => {
|
||||
const location = useLocation();
|
||||
const matches = matchRoutes(GuestAllows, location);
|
||||
const allowGuest = matches ? !!matches[0].pathname : false;
|
||||
const { data: loginConfig, isSuccess: loginConfigSuccess } = useGetLoginConfigQuery();
|
||||
const { isLoading: checkingInitialized } = useGetInitializedQuery();
|
||||
const {
|
||||
data: loginConfig,
|
||||
isUninitialized: loginConfigUninitialized,
|
||||
isLoading: loginConfigLoading
|
||||
} = useGetLoginConfigQuery(undefined, {
|
||||
refetchOnMountOrArgChange: true
|
||||
});
|
||||
const { isUninitialized: initializedUninitialized, isLoading: initLoading } =
|
||||
useGetInitializedQuery(undefined, {
|
||||
refetchOnMountOrArgChange: true
|
||||
});
|
||||
const { token, guest, initialized } = useAppSelector((store) => store.authData);
|
||||
|
||||
console.info(
|
||||
"uninitialized",
|
||||
initializedUninitialized,
|
||||
initializedUninitialized,
|
||||
loginConfigLoading,
|
||||
initLoading
|
||||
);
|
||||
// 初始化和login配置检查
|
||||
if (checkingInitialized || !loginConfigSuccess) return <Loading fullscreen={true} />;
|
||||
if (initializedUninitialized || loginConfigUninitialized)
|
||||
return <Loading fullscreen={true} context="auth-route" />;
|
||||
// 未初始化 则先走setup 流程
|
||||
if (!initialized) return <Navigate to={`/onboarding`} replace />;
|
||||
// 开启guest 并且没token 而且是允许guest访问的路由 则先去过渡页登录
|
||||
@@ -43,7 +59,6 @@ const RequireAuth: FC<Props> = ({ children, redirectTo = "/login" }) => {
|
||||
}
|
||||
// 登陆者是guest,并且不允许访问
|
||||
if (token && guest && !allowGuest) return <Navigate to={"/"} replace />;
|
||||
// console.log("authhhhh", allowGuest, token, guest);
|
||||
const tryPath = localStorage.getItem(KEY_LOCAL_TRY_PATH);
|
||||
if (tryPath) {
|
||||
localStorage.removeItem(KEY_LOCAL_TRY_PATH);
|
||||
|
||||
Reference in New Issue
Block a user