MCPcopy
hub / github.com/msgbyte/tianji / handler

Function handler

packages/cli/src/commands/login.ts:17–96  ·  view source on GitHub ↗
(argv: Arguments<LoginOptions>)

Source from the content-addressed store, hash-verified

15};
16
17export const handler = async (argv: Arguments<LoginOptions>): Promise<void> => {
18 console.log(chalk.cyan('\n🔐 Login to Tianji\n'));
19
20 try {
21 const response = await prompts([
22 {
23 type: 'text',
24 name: 'serverUrl',
25 message: 'Tianji server URL:',
26 initial: 'https://tianji.example.com',
27 validate: (value) =>
28 value.startsWith('http://') || value.startsWith('https://')
29 ? true
30 : 'Please enter a valid URL (http:// or https://)',
31 },
32 {
33 type: 'text',
34 name: 'workspaceId',
35 message: 'Workspace ID:',
36 validate: (value) =>
37 value.length > 0 ? true : 'Workspace ID is required',
38 },
39 {
40 type: 'password',
41 name: 'apiKey',
42 message: 'API Key:',
43 validate: (value) => (value.length > 0 ? true : 'API Key is required'),
44 },
45 ]);
46
47 // Check if user cancelled the prompts
48 if (!response.serverUrl || !response.workspaceId || !response.apiKey) {
49 console.log(chalk.yellow('\n❌ Login cancelled\n'));
50 process.exit(0);
51 }
52
53 const spinner = ora('Verifying credentials...').start();
54
55 // Test the connection
56 const apiClient = createAPIClient({
57 serverUrl: response.serverUrl,
58 workspaceId: response.workspaceId,
59 apiKey: response.apiKey,
60 });
61
62 const isValid = await apiClient.testConnection();
63
64 if (!isValid) {
65 spinner.fail(chalk.red('Invalid credentials'));
66 console.error(
67 chalk.red(
68 '\nPlease check your server URL, workspace ID, and API key.\n'
69 )
70 );
71 process.exit(1);
72 }
73
74 // Save the configuration

Callers

nothing calls this directly

Calls 6

createAPIClientFunction · 0.85
saveGlobalConfigFunction · 0.85
logMethod · 0.80
startMethod · 0.80
testConnectionMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected