fix: update login error

This commit is contained in:
2025-03-23 12:17:06 +08:00
parent 4b16ec8499
commit d56c4c15f2
8 changed files with 25 additions and 55 deletions

View File

@@ -65,7 +65,10 @@ const loginCommand = new Command('login')
program.addCommand(loginCommand);
const showMe = async (show = true) => {
const me = await queryLogin.getMe();
let me = await queryLogin.getMe();
if (me.code === 401) {
me = await queryLogin.getMe();
}
if (show) {
console.log('Me', me.data);
}
@@ -84,7 +87,12 @@ const switchOrgCommand = new Command('switch').argument('<username>', 'Switch to
program.addCommand(switchOrgCommand);
const command = new Command('me').description('').action(async () => {
await showMe();
try {
const res = await showMe(false);
console.log('me', res?.data);
} catch (error) {
console.log('me error', error);
}
});
program.addCommand(command);

View File

@@ -12,7 +12,7 @@ const tokenList = new Command('list')
.description('show token list')
// .option('-r --remove <number>', 'remove token by number')
.action(async (opts) => {
const res = queryLogin.cache.cache.cacheData;
const res = queryLogin.cacheStore.cacheData;
console.log(util.inspect(res, { colors: true, depth: 4 }));
});
token.addCommand(tokenList);

View File

@@ -1,19 +0,0 @@
import { program as app, Command } from '@/program.ts';
import { getConfig, writeConfig } from '@/module/index.ts';
import {queryMe} from '../query/index.ts';
// const command = new Command('me')
// .description('')
// .action(async () => {
// const config = getConfig()
// const res = await queryMe();
// if(res.code===200) {
// console.log('me', res.data)
// } else {
// console.log('not login')
// writeConfig({ ...config, token: '' });
// }
// });
// app.addCommand(command);

View File

@@ -2,7 +2,6 @@ import { program } from '@/program.ts';
import './command/login.ts';
import './command/logout.ts';
import './command/ls-token.ts';
import './command/me.ts';
import './command/deploy.ts';
import './command/serve.ts';
import './command/config.ts';

View File

@@ -34,20 +34,13 @@ query.beforeRequest = async (config) => {
};
query.afterResponse = async (response, ctx) => {
if (response.code === 401) {
if (query.stop) {
return {
code: 500,
message: '登录已过期',
};
}
query.stop = true;
const res = await queryLogin.afterCheck401ToRefreshToken(response, ctx);
query.stop = false;
return res;
console.log('401 after', response);
}
return response as any;
};
export const queryLogin = new QueryLoginNode({
query: query as any,
onLoad: async () => {},
onLoad: async () => {
// console.log('onLoad');
},
});