balibabu
commited on
Commit
·
bbbfe3a
1
Parent(s):
30910b7
feat: set initial state of auth to null (#108)
Browse files- web/.umirc.ts +1 -0
- web/src/hooks/authHook.ts +3 -2
- web/src/wrappers/auth.tsx +4 -2
web/.umirc.ts
CHANGED
@@ -21,6 +21,7 @@ export default defineConfig({
|
|
21 |
hack: `true; @import "~@/less/index.less";`,
|
22 |
},
|
23 |
},
|
|
|
24 |
proxy: {
|
25 |
'/v1': {
|
26 |
target: 'http://123.60.95.134:9380/',
|
|
|
21 |
hack: `true; @import "~@/less/index.less";`,
|
22 |
},
|
23 |
},
|
24 |
+
devtool: 'source-map',
|
25 |
proxy: {
|
26 |
'/v1': {
|
27 |
target: 'http://123.60.95.134:9380/',
|
web/src/hooks/authHook.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import authorizationUtil from '@/utils/authorizationUtil';
|
2 |
import { message } from 'antd';
|
3 |
import { useEffect, useMemo, useState } from 'react';
|
|
|
4 |
import { useNavigate, useSearchParams } from 'umi';
|
5 |
|
6 |
export const useLoginWithGithub = () => {
|
@@ -32,10 +33,10 @@ export const useLoginWithGithub = () => {
|
|
32 |
|
33 |
export const useAuth = () => {
|
34 |
const auth = useLoginWithGithub();
|
35 |
-
const [isLogin, setIsLogin] = useState(
|
36 |
|
37 |
useEffect(() => {
|
38 |
-
setIsLogin(!!
|
39 |
}, [auth]);
|
40 |
|
41 |
return { isLogin };
|
|
|
1 |
import authorizationUtil from '@/utils/authorizationUtil';
|
2 |
import { message } from 'antd';
|
3 |
import { useEffect, useMemo, useState } from 'react';
|
4 |
+
import { Nullable } from 'typings';
|
5 |
import { useNavigate, useSearchParams } from 'umi';
|
6 |
|
7 |
export const useLoginWithGithub = () => {
|
|
|
33 |
|
34 |
export const useAuth = () => {
|
35 |
const auth = useLoginWithGithub();
|
36 |
+
const [isLogin, setIsLogin] = useState<Nullable<boolean>>(null);
|
37 |
|
38 |
useEffect(() => {
|
39 |
+
setIsLogin(!!authorizationUtil.getAuthorization() || !!auth);
|
40 |
}, [auth]);
|
41 |
|
42 |
return { isLogin };
|
web/src/wrappers/auth.tsx
CHANGED
@@ -3,9 +3,11 @@ import { Navigate, Outlet } from 'umi';
|
|
3 |
|
4 |
export default () => {
|
5 |
const { isLogin } = useAuth();
|
6 |
-
if (isLogin) {
|
7 |
return <Outlet />;
|
8 |
-
} else {
|
9 |
return <Navigate to="/login" />;
|
10 |
}
|
|
|
|
|
11 |
};
|
|
|
3 |
|
4 |
export default () => {
|
5 |
const { isLogin } = useAuth();
|
6 |
+
if (isLogin === true) {
|
7 |
return <Outlet />;
|
8 |
+
} else if (isLogin === false) {
|
9 |
return <Navigate to="/login" />;
|
10 |
}
|
11 |
+
|
12 |
+
return <></>;
|
13 |
};
|