fix: 更新用户信息命令以使用新的获取令牌逻辑,并优化本地用户检查功能

This commit is contained in:
2026-02-21 22:19:30 +08:00
parent c0edd2cbbf
commit a4a5ed0b50
3 changed files with 52 additions and 43 deletions

View File

@@ -7,7 +7,7 @@ const me = new Command('me')
.action(async () => {
const aq = new AssistantQuery(assistantConfig);
await aq.init()
const info = await aq.queryLogin.checkLocalUser()
const info = await aq.getToken()
logger.info(info);
});

View File

@@ -257,17 +257,22 @@ export class AssistantApp extends Manager {
* 检查本地用户登录状态,如果未登录且存在 CNB_TOKEN则尝试使用 CNB_TOKEN 登录并更新用户信息
*/
async checkLocalUser() {
const config = this.config.getConfig();
return checkLocalUser({ assistantApp: this });
}
}
const checkLocalUser = async (opts: { assistantApp: AssistantApp }) => {
const { assistantApp } = opts;
const config = assistantApp.config.getConfig();
const auth = config?.auth;
let checkCNB = false;
if (!auth?.username) {
checkCNB = true;
// 没有登录过自动检测ci进行登录
// 检测条件1环境变量中存在 CNB_TOKEN
} else {
let temp = await assistantQuery.queryLogin.getToken()
if (temp) {
const isExpired = await assistantQuery.queryLogin.checkTokenValid()
console.log('Token 是否过期', isExpired);
}
let temp = await assistantQuery.getToken()
logger.info('[assistant] 当前登录用户', auth.username, 'token有效性检查结果', !!temp);
}
const cnbToken = useKey('CNB_TOKEN');
@@ -292,7 +297,7 @@ export class AssistantApp extends Manager {
if (!app?.id) {
app.id = 'dev-cnb'
}
this.config.setConfig({
assistantApp.config.setConfig({
auth,
app
});
@@ -302,4 +307,3 @@ export class AssistantApp extends Manager {
}
}
}
}

View File

@@ -35,7 +35,12 @@ export class AssistantQuery {
get(body: any, options?: DataOpts) {
return this.query.get(body, options);
}
getToken() {
return this.queryLogin.getToken();
async getToken() {
const token = await this.queryLogin.getToken();
if (!token) return '';
const isExpired = await this.queryLogin.checkTokenValid()
console.log('Token 是否过期', isExpired, token);
console.log('info', this.queryLogin.cacheStore.cacheData)
return token;
}
}