Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

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

haitaoobdd00e636b09
diff --git a/ui/src/pages/UserCenter/Auth/components/WeCom/index.tsx b/ui/src/pages/UserCenter/Auth/components/WeCom/index.tsx
index 0ba20ac6..c9c1f6be 100644
--- a/ui/src/pages/UserCenter/Auth/components/WeCom/index.tsx
+++ b/ui/src/pages/UserCenter/Auth/components/WeCom/index.tsx
@@ -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);
diff --git a/ui/src/stores/loggedUserInfo.ts b/ui/src/stores/loggedUserInfo.ts
index d08cce44..2e2b6afd 100644
--- a/ui/src/stores/loggedUserInfo.ts
+++ b/ui/src/stores/loggedUserInfo.ts
@@ -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';
}
diff --git a/ui/src/utils/guard.ts b/ui/src/utils/guard.ts
index 6e208360..cff941d8 100644
--- a/ui/src/utils/guard.ts
+++ b/ui/src/utils/guard.ts
@@ -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, {