添加两步验证

This commit is contained in:
hanhh
2021-08-30 23:37:26 +08:00
parent 3a998a37f0
commit 86c3e9a843
11 changed files with 592 additions and 154 deletions
+19 -1
View File
@@ -19,6 +19,7 @@ import { useCtx, useTheme } from '@/utils/hooks';
export default function (props: any) {
const ctx = useCtx();
const theme = useTheme();
const [user, setUser] = useState<any>();
const logout = () => {
request.post(`${config.apiPrefix}logout`).then(() => {
@@ -27,12 +28,29 @@ export default function (props: any) {
});
};
const getUser = () => {
request
.get(`${config.apiPrefix}user`)
.then((data) => {
if (data.data.username) {
setUser(data.data);
}
})
.catch((e) => {
if (e.response && e.response.status === 401) {
localStorage.removeItem(config.authKey);
history.push('/login');
}
});
};
useEffect(() => {
const isAuth = localStorage.getItem(config.authKey);
if (!isAuth) {
history.push('/login');
}
vhCheck();
getUser();
// patch custome layout title as react node [object, object]
document.title = '控制面板';
@@ -112,7 +130,7 @@ export default function (props: any) {
{...defaultProps}
>
{React.Children.map(props.children, (child) => {
return React.cloneElement(child, { ...ctx, ...theme });
return React.cloneElement(child, { ...ctx, ...theme, user });
})}
</ProLayout>
);