From b69b5dd4e59de6adc2034e33979e0fed7407d37d Mon Sep 17 00:00:00 2001
From: balibabu <cike8899@users.noreply.github.com>
Date: Thu, 7 Mar 2024 15:32:12 +0800
Subject: [PATCH] feat: set initial state of auth to null (#108)

---
 web/.umirc.ts             | 1 +
 web/src/hooks/authHook.ts | 5 +++--
 web/src/wrappers/auth.tsx | 6 ++++--
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/web/.umirc.ts b/web/.umirc.ts
index 4ecbc3c..6c72be6 100644
--- a/web/.umirc.ts
+++ b/web/.umirc.ts
@@ -21,6 +21,7 @@ export default defineConfig({
       hack: `true; @import "~@/less/index.less";`,
     },
   },
+  devtool: 'source-map',
   proxy: {
     '/v1': {
       target: 'http://123.60.95.134:9380/',
diff --git a/web/src/hooks/authHook.ts b/web/src/hooks/authHook.ts
index 75b2d26..d4bf85f 100644
--- a/web/src/hooks/authHook.ts
+++ b/web/src/hooks/authHook.ts
@@ -1,6 +1,7 @@
 import authorizationUtil from '@/utils/authorizationUtil';
 import { message } from 'antd';
 import { useEffect, useMemo, useState } from 'react';
+import { Nullable } from 'typings';
 import { useNavigate, useSearchParams } from 'umi';
 
 export const useLoginWithGithub = () => {
@@ -32,10 +33,10 @@ export const useLoginWithGithub = () => {
 
 export const useAuth = () => {
   const auth = useLoginWithGithub();
-  const [isLogin, setIsLogin] = useState(true);
+  const [isLogin, setIsLogin] = useState<Nullable<boolean>>(null);
 
   useEffect(() => {
-    setIsLogin(!!auth || !!authorizationUtil.getAuthorization());
+    setIsLogin(!!authorizationUtil.getAuthorization() || !!auth);
   }, [auth]);
 
   return { isLogin };
diff --git a/web/src/wrappers/auth.tsx b/web/src/wrappers/auth.tsx
index 2f0b803..f12ebaf 100644
--- a/web/src/wrappers/auth.tsx
+++ b/web/src/wrappers/auth.tsx
@@ -3,9 +3,11 @@ import { Navigate, Outlet } from 'umi';
 
 export default () => {
   const { isLogin } = useAuth();
-  if (isLogin) {
+  if (isLogin === true) {
     return <Outlet />;
-  } else {
+  } else if (isLogin === false) {
     return <Navigate to="/login" />;
   }
+
+  return <></>;
 };
-- 
GitLab