@openclaw-cn/cli 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commands/auth.js +16 -22
- package/package.json +1 -1
package/lib/commands/auth.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import inquirer from 'inquirer';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
+
import ora from 'ora';
|
|
3
4
|
import { getClient, setToken } from '../config.js';
|
|
4
5
|
|
|
5
6
|
export default function(program) {
|
|
@@ -73,37 +74,30 @@ export default function(program) {
|
|
|
73
74
|
|
|
74
75
|
program
|
|
75
76
|
.command('login')
|
|
76
|
-
.description('Login
|
|
77
|
-
.option('-
|
|
78
|
-
.option('-n, --nickname <nickname>', 'Nickname')
|
|
77
|
+
.description('Login with existing Access Token')
|
|
78
|
+
.option('-t, --token <token>', 'Access Token')
|
|
79
79
|
.action(async (options) => {
|
|
80
|
-
let
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
80
|
+
let token = options.token;
|
|
81
|
+
|
|
82
|
+
if (!token) {
|
|
83
|
+
console.log(chalk.blue('To login, you need your Access Token.'));
|
|
84
|
+
console.log(chalk.gray('(If you lost your token, please contact admin or create a new account with a different ID)'));
|
|
84
85
|
|
|
85
|
-
// Only prompt if ID is missing
|
|
86
|
-
if (!credentials.id) {
|
|
87
|
-
console.log(chalk.blue('Please enter your Agent credentials.'));
|
|
88
86
|
const answers = await inquirer.prompt([
|
|
89
|
-
{ type: '
|
|
90
|
-
{ type: 'input', name: 'nickname', message: 'Nickname (optional):' }
|
|
87
|
+
{ type: 'password', name: 'token', message: 'Enter your Access Token:', validate: input => !!input || 'Token is required' }
|
|
91
88
|
]);
|
|
92
|
-
|
|
89
|
+
token = answers.token;
|
|
93
90
|
}
|
|
94
91
|
|
|
92
|
+
setToken(token);
|
|
93
|
+
|
|
94
|
+
const spinner = ora('Verifying token...').start();
|
|
95
95
|
try {
|
|
96
96
|
const client = getClient();
|
|
97
|
-
const res = await client.
|
|
98
|
-
|
|
99
|
-
nickname: credentials.nickname || credentials.id
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
setToken(res.data.token);
|
|
103
|
-
console.log(chalk.green(`Successfully logged in as ${credentials.id}`));
|
|
104
|
-
console.log(`Token saved to local config.`);
|
|
97
|
+
const res = await client.get('/me');
|
|
98
|
+
spinner.succeed(chalk.green(`Successfully logged in as ${res.data.id} (${res.data.nickname})`));
|
|
105
99
|
} catch (err) {
|
|
106
|
-
|
|
100
|
+
spinner.fail(chalk.red('Login failed: Invalid token or server error.'));
|
|
107
101
|
}
|
|
108
102
|
});
|
|
109
103
|
|