Browse Source

fix: 增加未登录判断

xyh 3 years ago
parent
commit
694ca9c92f

+ 6 - 2
packages/app/src/components/authentication/index.tsx

@@ -1,5 +1,4 @@
 import {FC, ReactNode} from 'react';
-import {Navigate} from 'react-router-dom';
 import {LOGIN_PATH} from '@routes';
 import {useStore} from 'zustand';
 import {userStore} from '@stores';
@@ -7,7 +6,12 @@ import {userStore} from '@stores';
 const Auth: FC<{children: ReactNode}> = function ({children}) {
   const token = useStore(userStore, state => state.token);
 
-  return <>{token.length ? children : <Navigate replace to={LOGIN_PATH} />}</>;
+  if (!token) {
+    parent ? parent.location.replace(LOGIN_PATH) : location.replace(LOGIN_PATH);
+    return null;
+  }
+
+  return <>{children}</>;
 };
 
 export default Auth;

+ 3 - 3
packages/app/src/components/table-search-provider/index.tsx

@@ -1,5 +1,5 @@
 import {TableSearchAction, useTableSearchContextReducer} from '@hooks';
-import {Footer} from '@components';
+import {Auth, Footer} from '@components';
 import {Dispatch, ReactElement, ReactNode} from 'react';
 import {Context} from 'use-context-selector';
 
@@ -18,10 +18,10 @@ function TableSearchProvider<T extends Record<string, unknown>>({
   const value = useTableSearchContextReducer(state);
 
   return (
-    <>
+    <Auth>
       <Provider value={value}>{children}</Provider>
       <Footer color='#bbb' />
-    </>
+    </Auth>
   );
 }
 

+ 1 - 1
packages/webpack/scripts/build.js

@@ -87,7 +87,7 @@ try {
       console.log();
       process.exit(1);
     }
-    const {assets, startTime, endTime} = stats.compilation.assets;
+    const {assets, startTime, endTime} = stats.compilation;
     const time = endTime - startTime;
     clearConsole();
     console.log();