处理refreshToken, token disable返回空字符串的情况

This commit is contained in:
wkj 2024-04-23 20:03:31 +08:00
parent a491130190
commit aa55749e63
3 changed files with 18 additions and 13 deletions

View File

@ -1847,7 +1847,7 @@ export async function refreshToken<ED extends EntityDict>(
context: BRC<ED>
) {
const { env, tokenValue } = params;
const fn = context.openRootMode();
const closeRootMode = context.openRootMode();
let [token] = await context.select('token', {
data: Object.assign({
env: 1,
@ -1864,13 +1864,12 @@ export async function refreshToken<ED extends EntityDict>(
await context.operate('token', {
id: await generateNewIdAsync(),
action: 'disable',
data: {
},
data: {},
filter: {
id: token.id,
}
}, { dontCollect: true });
fn();
closeRootMode();
return '';
}
if (process.env.OAK_PLATFORM === 'server') {
@ -1902,10 +1901,10 @@ export async function refreshToken<ED extends EntityDict>(
},
{}
);
fn();
closeRootMode();
return newValue;
}
}
fn();
closeRootMode();
return tokenValue;
}

View File

@ -7,10 +7,8 @@ import { EntityDict } from '../oak-app-domain';
import { RuntimeContext } from './RuntimeContext';
import { Application } from '../features/application';
import { Token } from '../features/token';
import GeneralAspectDict from '../aspects/AspectDict';
import { SyncRowStore } from 'oak-domain/lib/store/SyncRowStore';
import { FeatureDict } from '../features';
import { BackendRuntimeContext } from './BackendRuntimeContext';
import {
OakApplicationLoadingException,
OakTokenExpiredException,

View File

@ -4,6 +4,7 @@ import {
OakUnloggedInException,
OakUserUnpermittedException,
OakNetworkException,
OakServerProxyException,
} from 'oak-domain/lib/types/Exception';
import { Cache } from 'oak-frontend-base/es/features/cache';
import { LocalStorage } from 'oak-frontend-base/es/features/localStorage';
@ -41,7 +42,7 @@ export class Token<ED extends EntityDict> extends Feature {
if (
process.env.OAK_PLATFORM === 'web' &&
(process.env.NODE_ENV !== 'development' ||
process.env.PROD === 'true')
process.env.PROD === 'true' || process.env.OAK_DEV_MODE === 'server')
) {
// 纯前台模式 多窗口时不监听storage
// 在web下可能多窗口一个窗口更新了token其它窗口应跟着变
@ -75,16 +76,23 @@ export class Token<ED extends EntityDict> extends Feature {
true
);
if (this.tokenValue !== result) {
this.tokenValue = result;
await this.storage.save(LOCAL_STORAGE_KEYS.token, result);
// 如果返回空字符串token被disabledtokenValue置为undefined
if (result) {
this.tokenValue = result;
await this.storage.save(LOCAL_STORAGE_KEYS.token, result);
} else {
this.removeToken(true);
}
}
} catch (err) {
// refresh出了任何错都无视(排除网络异常)直接放弃此token
console.warn(err);
if (err instanceof OakNetworkException) {
if (
err instanceof OakNetworkException ||
err instanceof OakServerProxyException
) {
return;
}
this.tokenValue = undefined;
this.removeToken(true);
}
}