feat: set initial state of auth to null (#108)

This commit is contained in:
balibabu 2024-03-07 15:32:12 +08:00 committed by GitHub
parent cfc3b62e77
commit b69b5dd4e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 4 deletions

View File

@ -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/',

View File

@ -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 };

View File

@ -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 <></>;
};