fix:解决刷新页面没有 Token

feature/price_manager
Jimmy Liow 1 year ago
parent 9fef49263b
commit a1890df323

@ -5,6 +5,7 @@ import { DownOutlined } from '@ant-design/icons';
import 'antd/dist/reset.css';
import AppLogo from '@/assets/logo-gh.png';
import { isEmpty } from '@/utils/commons';
import { appendRequestParams } from '@/utils/request'
import Language from '../i18n/LanguageSwitcher';
import { useTranslation } from 'react-i18next';
import zhLocale from 'antd/locale/zh_CN';
@ -24,38 +25,34 @@ function App() {
const [password, setPassword] = useState('');
const { notification } = AntApp.useApp();
const loginUser = useAuthStore((state) => state.loginUser)
const [loginUser, validateUserPassword] = useAuthStore((state) => state.loginUser, state.validateUserPassword)
const { loginToken } = useStorage()
const noticeUnRead = useNoticeStore((state) => state.noticeUnRead);
const noticeUnRead = useNoticeStore((state) => state.noticeUnRead)
const href = useHref();
const navigate = useNavigate()
const location = useLocation()
// /p...
const needToLogin = href !== '/login' && isEmpty(loginToken)
if (!needToLogin) {
appendRequestParams('token', loginToken)
}
useEffect(() => {
if (href !== '/login' && isEmpty(loginToken)) {
navigate('/login');
if (needToLogin) {
navigate('/login')
}
}, [href]);
}, [href])
useEffect(() => {
window.gtag('event', 'page_view', { page_location: window.location.href });
}, [location]);
const onSubmit = () => {
authStore.valdateUserPassword(loginUser.username, password)
.then(() => {
authStore.fetchUserDetail()
.catch(ex => {
notification.error({
message: `Notification`,
description: 'Failed to get user information.',
placement: 'top',
duration: 4,
});
});
})
valdateUserPassword(loginUser.username, password)
.catch(ex => {
notification.error({
message: `Notification`,
@ -181,7 +178,7 @@ function App() {
minHeight: 280,
background: colorBgContainer,
}}>
<Outlet />
{needToLogin ? <>login...</> : <Outlet />}
</Content>
<Footer></Footer>
</Layout>

Loading…
Cancel
Save