Skip to content
Snippets Groups Projects
Unverified Commit b69b5dd4 authored by balibabu's avatar balibabu Committed by GitHub
Browse files

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

parent cfc3b62e
No related branches found
No related tags found
No related merge requests found
...@@ -21,6 +21,7 @@ export default defineConfig({ ...@@ -21,6 +21,7 @@ export default defineConfig({
hack: `true; @import "~@/less/index.less";`, hack: `true; @import "~@/less/index.less";`,
}, },
}, },
devtool: 'source-map',
proxy: { proxy: {
'/v1': { '/v1': {
target: 'http://123.60.95.134:9380/', target: 'http://123.60.95.134:9380/',
......
import authorizationUtil from '@/utils/authorizationUtil'; import authorizationUtil from '@/utils/authorizationUtil';
import { message } from 'antd'; import { message } from 'antd';
import { useEffect, useMemo, useState } from 'react'; import { useEffect, useMemo, useState } from 'react';
import { Nullable } from 'typings';
import { useNavigate, useSearchParams } from 'umi'; import { useNavigate, useSearchParams } from 'umi';
export const useLoginWithGithub = () => { export const useLoginWithGithub = () => {
...@@ -32,10 +33,10 @@ export const useLoginWithGithub = () => { ...@@ -32,10 +33,10 @@ export const useLoginWithGithub = () => {
export const useAuth = () => { export const useAuth = () => {
const auth = useLoginWithGithub(); const auth = useLoginWithGithub();
const [isLogin, setIsLogin] = useState(true); const [isLogin, setIsLogin] = useState<Nullable<boolean>>(null);
useEffect(() => { useEffect(() => {
setIsLogin(!!auth || !!authorizationUtil.getAuthorization()); setIsLogin(!!authorizationUtil.getAuthorization() || !!auth);
}, [auth]); }, [auth]);
return { isLogin }; return { isLogin };
......
...@@ -3,9 +3,11 @@ import { Navigate, Outlet } from 'umi'; ...@@ -3,9 +3,11 @@ import { Navigate, Outlet } from 'umi';
export default () => { export default () => {
const { isLogin } = useAuth(); const { isLogin } = useAuth();
if (isLogin) { if (isLogin === true) {
return <Outlet />; return <Outlet />;
} else { } else if (isLogin === false) {
return <Navigate to="/login" />; return <Navigate to="/login" />;
} }
return <></>;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment