fix(auth-landing): Improve the stability of the process of obtaining login user information

This commit is contained in:
haitaoo 2023-04-25 16:22:32 +08:00
parent f89687d021
commit bdd00e636b
3 changed files with 21 additions and 14 deletions

View File

@ -1,6 +1,7 @@
import React, { memo, FC, useState, useEffect } from 'react';
import { Card } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
import { useNavigate } from 'react-router-dom';
import QrCode from 'qrcode';
@ -13,6 +14,7 @@ import { getLoginConf, checkLoginResult } from './service';
let checkTimer: NodeJS.Timeout;
const Index: FC = () => {
const { t } = useTranslation('translation', { keyPrefix: 'plugins' });
const navigate = useNavigate();
const ucAgent = userCenterStore().agent;
const agentName = ucAgent?.agent_info?.name || '';
const [qrcodeDataUrl, setQrCodeDataUrl] = useState('');
@ -22,7 +24,7 @@ const Index: FC = () => {
}
checkLoginResult(key).then((res) => {
if (res.is_login) {
guard.handleLoginWithToken(res.token);
guard.handleLoginWithToken(res.token, navigate);
return;
}
clearTimeout(checkTimer);

View File

@ -31,6 +31,9 @@ const initUser: UserInfoRes = {
const loggedUserInfo = create<UserInfoStore>((set) => ({
user: initUser,
update: (params) => {
if (typeof params !== 'object' || !params) {
return;
}
if (!params?.language) {
params.language = 'Default';
}

View File

@ -338,19 +338,21 @@ export const handleLoginWithToken = (
) => {
if (token) {
Storage.set(LOGGED_TOKEN_STORAGE_KEY, token);
getLoggedUserInfo().then((res) => {
loggedUserInfoStore.getState().update(res);
const userStat = deriveLoginState();
if (userStat.isNotActivated) {
floppyNavigation.navigate(RouteAlias.inactive, {
handler,
options: {
replace: true,
},
});
} else {
handleLoginRedirect(handler);
}
setTimeout(() => {
getLoggedUserInfo().then((res) => {
loggedUserInfoStore.getState().update(res);
const userStat = deriveLoginState();
if (userStat.isNotActivated) {
floppyNavigation.navigate(RouteAlias.inactive, {
handler,
options: {
replace: true,
},
});
} else {
handleLoginRedirect(handler);
}
});
});
} else {
floppyNavigation.navigate(RouteAlias.home, {