Unverified Commit 557384e6 authored by Zzm0809's avatar Zzm0809 Committed by GitHub

[Fix] Fix token may get empty and cause page crash (#3254)

parent ca5d7468
...@@ -35,7 +35,7 @@ test.msg.job.log.url=Click to view the exception log for this task ...@@ -35,7 +35,7 @@ test.msg.job.log.url=Click to view the exception log for this task
user.assign.role.success=User Assign Role Success user.assign.role.success=User Assign Role Success
global.params.check.error.value=Field: {0}, Illegal Value: {1} global.params.check.error.value=Field: {0}, Illegal Value: {1}
change.password.success=Change Password Success change.password.success=Change Password Success
user.not.exist=User:{0} Not Exist user.not.exist=User Not Exist
refresh.success=Refresh Successfully refresh.success=Refresh Successfully
ds.get.node.list.error=Get Node List Error ds.get.node.list.error=Get Node List Error
ldap.default.tenant.nofound=The LDAP default tenant does not exist ldap.default.tenant.nofound=The LDAP default tenant does not exist
......
...@@ -35,7 +35,7 @@ test.msg.job.log.url=点击查看该任务的异常日志 ...@@ -35,7 +35,7 @@ test.msg.job.log.url=点击查看该任务的异常日志
user.assign.role.success=用户分配角色成功 user.assign.role.success=用户分配角色成功
global.params.check.error.value=字段: {0}, 不合法的值: {1} global.params.check.error.value=字段: {0}, 不合法的值: {1}
change.password.success=修改密码成功 change.password.success=修改密码成功
user.not.exist=用户:{0} 不存在 user.not.exist=用户不存在
refresh.success=刷新成功 refresh.success=刷新成功
ds.get.node.list.error=节点获取失败 ds.get.node.list.error=节点获取失败
ldap.default.tenant.nofound=LDAP默认租户不存在 ldap.default.tenant.nofound=LDAP默认租户不存在
......
...@@ -36,7 +36,7 @@ export const gotoRedirectUrl = () => { ...@@ -36,7 +36,7 @@ export const gotoRedirectUrl = () => {
export const redirectToLogin = () => { export const redirectToLogin = () => {
//TODO: 弹出确认框 //TODO: 弹出确认框
window.location.href = '/login'; window.location.href = '/user/login';
}; };
export const initSomeThing = () => { export const initSomeThing = () => {
......
...@@ -24,7 +24,7 @@ import LangSwitch from '@/pages/Other/Login/LangSwitch'; ...@@ -24,7 +24,7 @@ import LangSwitch from '@/pages/Other/Login/LangSwitch';
import { chooseTenantSubmit, login, queryDataByParams } from '@/services/BusinessCrud'; import { chooseTenantSubmit, login, queryDataByParams } from '@/services/BusinessCrud';
import { API } from '@/services/data'; import { API } from '@/services/data';
import { API_CONSTANTS } from '@/services/endpoints'; import { API_CONSTANTS } from '@/services/endpoints';
import { UserBaseInfo } from '@/types/AuthCenter/data'; import { SaTokenInfo, UserBaseInfo } from '@/types/AuthCenter/data.d';
import { setTenantStorageAndCookie } from '@/utils/function'; import { setTenantStorageAndCookie } from '@/utils/function';
import { useLocalStorage } from '@/utils/hook/useLocalStorage'; import { useLocalStorage } from '@/utils/hook/useLocalStorage';
import { l } from '@/utils/intl'; import { l } from '@/utils/intl';
...@@ -67,7 +67,8 @@ const Login: React.FC = () => { ...@@ -67,7 +67,8 @@ const Login: React.FC = () => {
* When the token is expired, redirect to login * When the token is expired, redirect to login
*/ */
useEffect(() => { useEffect(() => {
const expirationTime = JSON.parse(JSON.stringify(localStorageOfToken)).tokenTimeout ?? 0; // GET TOKEN TIMEOUT const expirationTime =
(JSON.parse(JSON.stringify(localStorageOfToken)) as SaTokenInfo)?.tokenTimeout ?? 0; // GET TOKEN TIMEOUT
let timeRemaining = 0; let timeRemaining = 0;
let timer: NodeJS.Timeout; let timer: NodeJS.Timeout;
if (expirationTime > 0) { if (expirationTime > 0) {
...@@ -138,9 +139,15 @@ const Login: React.FC = () => { ...@@ -138,9 +139,15 @@ const Login: React.FC = () => {
const result = await login({ ...values }); const result = await login({ ...values });
if (result.code === 0) { if (result.code === 0) {
// if login success then get token info and set it to local storage // if login success then get token info and set it to local storage
await queryDataByParams(API_CONSTANTS.TOKEN_INFO).then((res) => await queryDataByParams<SaTokenInfo>(API_CONSTANTS.TOKEN_INFO).then((res) => {
setLocalStorageOfToken(JSON.stringify(res)) console.log(res);
); if (res) {
setLocalStorageOfToken(JSON.stringify(res));
} else {
// 如果没有获取到token信息,直接跳转到登录页
redirectToLogin();
}
});
} }
setInitialState((s) => ({ ...s, currentUser: result.data })); setInitialState((s) => ({ ...s, currentUser: result.data }));
await SuccessMessageAsync(l('login.result', '', { msg: result.msg, time: result.time })); await SuccessMessageAsync(l('login.result', '', { msg: result.msg, time: result.time }));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment