fix: 修复账号被删除后流程被卡死的问题

pull/81/head
moonrailgun 3 years ago
parent 8d18e70233
commit ab52a5f8b4

@ -30,7 +30,7 @@
"k35abe359": "Lobby",
"k35f486ba": "Nickname",
"k35f990b0": "View Detail",
"k3ac17670": "An exception occurred, store creation failed",
"k3ac17670": "An exception occurred, store create failed",
"k3b4b656d": "About",
"k3bbf3bbd": "Register Account",
"k3c502edb": "E-mail can not be empty",

@ -24,16 +24,20 @@ import { setGlobalSocket, setGlobalStore } from '@/utils/global-state-helper';
function useAppState() {
const history = useHistory();
const { value, loading } = useAsync(async () => {
const { value, loading, error } = useAsync(async () => {
let userLoginInfo = getGlobalUserLoginInfo();
if (_isNil(userLoginInfo)) {
// 如果没有全局缓存的数据, 则尝试自动登录
try {
const token = await getUserJWT();
if (typeof token !== 'string') {
throw new Error('Token 不合法');
throw new Error('Token 格式不合法');
}
userLoginInfo = await loginWithToken(token);
if (userLoginInfo === null) {
throw new Error('Token 内容不合法');
}
} catch (e) {
// 当前 Token 不存在或已过期
history.replace(
@ -62,7 +66,7 @@ function useAppState() {
const store = value?.store;
const socket = value?.socket;
return { loading, store, socket };
return { loading, store, socket, error };
}
/**
@ -70,7 +74,7 @@ function useAppState() {
*
*/
export const MainProvider: React.FC = React.memo((props) => {
const { loading, store } = useAppState();
const { loading, store, error } = useAppState();
if (loading) {
return (
@ -80,6 +84,11 @@ export const MainProvider: React.FC = React.memo((props) => {
);
}
if (error) {
console.error('[MainProvider]', error);
return <div>{error.message}</div>;
}
if (_isNil(store)) {
return <div>{t('出现异常, Store 创建失败')}</div>;
}

Loading…
Cancel
Save