fix: 更新用户信息命令以使用新的获取令牌逻辑,并优化本地用户检查功能
This commit is contained in:
@@ -7,7 +7,7 @@ const me = new Command('me')
|
|||||||
.action(async () => {
|
.action(async () => {
|
||||||
const aq = new AssistantQuery(assistantConfig);
|
const aq = new AssistantQuery(assistantConfig);
|
||||||
await aq.init()
|
await aq.init()
|
||||||
const info = await aq.queryLogin.checkLocalUser()
|
const info = await aq.getToken()
|
||||||
logger.info(info);
|
logger.info(info);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -257,17 +257,22 @@ export class AssistantApp extends Manager {
|
|||||||
* 检查本地用户登录状态,如果未登录且存在 CNB_TOKEN,则尝试使用 CNB_TOKEN 登录并更新用户信息
|
* 检查本地用户登录状态,如果未登录且存在 CNB_TOKEN,则尝试使用 CNB_TOKEN 登录并更新用户信息
|
||||||
*/
|
*/
|
||||||
async checkLocalUser() {
|
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;
|
const auth = config?.auth;
|
||||||
let checkCNB = false;
|
let checkCNB = false;
|
||||||
if (!auth?.username) {
|
if (!auth?.username) {
|
||||||
checkCNB = true;
|
checkCNB = true;
|
||||||
|
// 没有登录过,自动检测ci进行登录
|
||||||
|
// 检测条件1:环境变量中存在 CNB_TOKEN
|
||||||
} else {
|
} else {
|
||||||
let temp = await assistantQuery.queryLogin.getToken()
|
let temp = await assistantQuery.getToken()
|
||||||
if (temp) {
|
|
||||||
const isExpired = await assistantQuery.queryLogin.checkTokenValid()
|
|
||||||
console.log('Token 是否过期', isExpired);
|
|
||||||
}
|
|
||||||
logger.info('[assistant] 当前登录用户', auth.username, 'token有效性检查结果', !!temp);
|
logger.info('[assistant] 当前登录用户', auth.username, 'token有效性检查结果', !!temp);
|
||||||
}
|
}
|
||||||
const cnbToken = useKey('CNB_TOKEN');
|
const cnbToken = useKey('CNB_TOKEN');
|
||||||
@@ -292,7 +297,7 @@ export class AssistantApp extends Manager {
|
|||||||
if (!app?.id) {
|
if (!app?.id) {
|
||||||
app.id = 'dev-cnb'
|
app.id = 'dev-cnb'
|
||||||
}
|
}
|
||||||
this.config.setConfig({
|
assistantApp.config.setConfig({
|
||||||
auth,
|
auth,
|
||||||
app
|
app
|
||||||
});
|
});
|
||||||
@@ -301,5 +306,4 @@ export class AssistantApp extends Manager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -35,7 +35,12 @@ export class AssistantQuery {
|
|||||||
get(body: any, options?: DataOpts) {
|
get(body: any, options?: DataOpts) {
|
||||||
return this.query.get(body, options);
|
return this.query.get(body, options);
|
||||||
}
|
}
|
||||||
getToken() {
|
async getToken() {
|
||||||
return this.queryLogin.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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user