处理refreshToken, token disable返回空字符串的情况
This commit is contained in:
parent
a491130190
commit
aa55749e63
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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被disabled,tokenValue置为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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue