feat: call useLoginWithGithub in useAuth (#107)
This commit is contained in:
parent
2b2808c268
commit
cfc3b62e77
@ -1,15 +1,8 @@
|
||||
import authorizationUtil from '@/utils/authorizationUtil';
|
||||
import { useMemo, useState } from 'react';
|
||||
import { message } from 'antd';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { useNavigate, useSearchParams } from 'umi';
|
||||
|
||||
export const useAuth = () => {
|
||||
const [isLogin, setIsLogin] = useState(
|
||||
() => !!authorizationUtil.getAuthorization(),
|
||||
);
|
||||
|
||||
return { isLogin };
|
||||
};
|
||||
|
||||
export const useLoginWithGithub = () => {
|
||||
const [currentQueryParameters, setSearchParams] = useSearchParams();
|
||||
const error = currentQueryParameters.get('error');
|
||||
@ -20,6 +13,7 @@ export const useLoginWithGithub = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
if (error) {
|
||||
message.error(error);
|
||||
navigate('/login');
|
||||
newQueryParameters.delete('error');
|
||||
setSearchParams(newQueryParameters);
|
||||
@ -33,4 +27,16 @@ export const useLoginWithGithub = () => {
|
||||
newQueryParameters.delete('auth');
|
||||
setSearchParams(newQueryParameters);
|
||||
}
|
||||
return auth;
|
||||
};
|
||||
|
||||
export const useAuth = () => {
|
||||
const auth = useLoginWithGithub();
|
||||
const [isLogin, setIsLogin] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
setIsLogin(!!auth || !!authorizationUtil.getAuthorization());
|
||||
}, [auth]);
|
||||
|
||||
return { isLogin };
|
||||
};
|
||||
|
||||
@ -4,7 +4,6 @@ import { Outlet } from 'umi';
|
||||
import '../locales/config';
|
||||
import Header from './components/header';
|
||||
|
||||
import { useLoginWithGithub } from '@/hooks/authHook';
|
||||
import styles from './index.less';
|
||||
|
||||
const { Content } = Layout;
|
||||
@ -14,8 +13,6 @@ const App: React.FC = () => {
|
||||
token: { colorBgContainer, borderRadiusLG },
|
||||
} = theme.useToken();
|
||||
|
||||
useLoginWithGithub();
|
||||
|
||||
return (
|
||||
<Layout className={styles.layout}>
|
||||
<Layout>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user