mirror of https://gitee.com/answerdev/answer.git
fix(auth-landing): Improve the stability of the process of obtaining login user information
This commit is contained in:
parent
f89687d021
commit
bdd00e636b
|
@ -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);
|
||||
|
|
|
@ -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';
|
||||
}
|
||||
|
|
|
@ -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, {
|
||||
|
|
Loading…
Reference in New Issue