修正 token刷新时 页面一直显示loading异常

This commit is contained in:
wkj 2024-04-29 16:14:18 +08:00
parent 76c205cc90
commit 06322f39c6
7 changed files with 26 additions and 12 deletions

View File

@ -1351,6 +1351,11 @@ export async function refreshToken(params, context) {
assert(token);
const now = Date.now();
if (!checkTokenEnvConsistency(env, token.env)) {
console.log('####### refreshToken环境改变 start #######\n');
console.log(env);
console.log('---------------------\n');
console.log(token.env);
console.log('####### refreshToken环境改变 end #######\n');
await context.operate('token', {
id: await generateNewIdAsync(),
action: 'disable',

View File

@ -10,8 +10,8 @@ export class Token extends Feature {
cache;
storage;
async loadSavedToken() {
let tokenValue = await this.storage.load(LOCAL_STORAGE_KEYS.token);
await this.refreshTokenData(tokenValue);
this.tokenValue = await this.storage.load(LOCAL_STORAGE_KEYS.token);
await this.refreshTokenData(this.tokenValue);
this.publish();
}
constructor(cache, storage, environment) {
@ -46,13 +46,12 @@ export class Token extends Feature {
tokenValue,
env,
}, undefined, true, true);
if (this.tokenValue !== result) {
if (tokenValue !== result) {
// 如果返回空字符串token被disabledtokenValue置为undefined
if (result) {
this.tokenValue = result;
await this.storage.save(LOCAL_STORAGE_KEYS.token, result);
}
else {
} else {
this.removeToken(true);
}
}

View File

@ -1366,6 +1366,11 @@ async function refreshToken(params, context) {
(0, assert_1.assert)(token);
const now = Date.now();
if (!checkTokenEnvConsistency(env, token.env)) {
console.log('####### refreshToken环境改变 start #######\n');
console.log(env);
console.log('---------------------\n');
console.log(token.env);
console.log('####### refreshToken环境改变 end #######\n');
await context.operate('token', {
id: await (0, uuid_1.generateNewIdAsync)(),
action: 'disable',

View File

@ -13,8 +13,8 @@ class Token extends Feature_1.Feature {
cache;
storage;
async loadSavedToken() {
let tokenValue = await this.storage.load(constants_1.LOCAL_STORAGE_KEYS.token);
await this.refreshTokenData(tokenValue);
this.tokenValue = await this.storage.load(constants_1.LOCAL_STORAGE_KEYS.token);
await this.refreshTokenData(this.tokenValue);
this.publish();
}
constructor(cache, storage, environment) {
@ -49,7 +49,7 @@ class Token extends Feature_1.Feature {
tokenValue,
env,
}, undefined, true, true);
if (this.tokenValue !== result) {
if (tokenValue !== result) {
// 如果返回空字符串token被disabledtokenValue置为undefined
if (result) {
this.tokenValue = result;

View File

@ -42,7 +42,7 @@
"antd-mobile-icons": ">=0.3.0",
"react": ">=18.2.0",
"react-dom": ">=18.1.0",
"react-native": "^0.72.7",
"react-native": ">=0.72.7",
"react-router-dom": ">=6.3.0"
},
"devDependencies": {

View File

@ -1861,6 +1861,11 @@ export async function refreshToken<ED extends EntityDict>(
assert(token);
const now = Date.now();
if (!checkTokenEnvConsistency(env, token.env as WebEnv)) {
console.log('####### refreshToken 环境改变 start #######\n');
console.log(env);
console.log('---------------------\n');
console.log(token.env);
console.log('####### refreshToken 环境改变 end #######\n');
await context.operate('token', {
id: await generateNewIdAsync(),
action: 'disable',

View File

@ -23,8 +23,8 @@ export class Token<ED extends EntityDict> extends Feature {
private storage: LocalStorage;
private async loadSavedToken() {
let tokenValue = await this.storage.load(LOCAL_STORAGE_KEYS.token);
await this.refreshTokenData(tokenValue);
this.tokenValue = await this.storage.load(LOCAL_STORAGE_KEYS.token);
await this.refreshTokenData(this.tokenValue);
this.publish();
}
@ -73,7 +73,7 @@ export class Token<ED extends EntityDict> extends Feature {
true,
true
);
if (this.tokenValue !== result) {
if (tokenValue !== result) {
// 如果返回空字符串token被disabledtokenValue置为undefined
if (result) {
this.tokenValue = result;