fix: initialState refresh

This commit is contained in:
jialin
2024-08-27 14:15:29 +08:00
parent 2b1f5d38e1
commit 9a0aeb491a
6 changed files with 51 additions and 55 deletions
+8 -1
View File
@@ -1,6 +1,6 @@
import { userAtom } from '@/atoms/user';
import Footer from '@/components/footer';
import { history } from '@umijs/max';
import { history, useModel } from '@umijs/max';
import { useAtom } from 'jotai';
import { useEffect } from 'react';
import LoginForm from './components/login-form';
@@ -9,11 +9,18 @@ import styles from './components/styles.less';
const Login = () => {
const [userInfo, setUserInfo] = useAtom(userAtom);
const { initialState, setInitialState } = useModel('@@initialState') || {};
const gotoDefaultPage = (userInfo: any) => {
if (!userInfo || userInfo?.require_password_change) {
return;
}
if (!initialState?.currentUser) {
setInitialState((s: any) => ({
...s,
currentUser: userInfo
}));
}
const pathname = userInfo?.is_admin ? '/dashboard' : '/playground';
history.push(pathname, { replace: true });