MCPcopy Create free account
hub / github.com/acode/cli / run

Method run

cli/commands/login.js:33–144  ·  view source on GitHub ↗
(params, callback)

Source from the content-addressed store, hash-verified

31 }
32
33 run(params, callback) {
34
35 let host = params.flags.h ? params.flags.h[0] : 'https://api.autocode.com';
36 let port = params.flags.p && params.flags.p[0];
37
38 let email = params.vflags.email || params.vflags.email || []
39 email = email[0];
40 let password = params.vflags.password || params.vflags.password || [];
41 password = password[0];
42
43 let questions = [];
44
45 email || questions.push({
46 name: 'email',
47 type: 'input',
48 default: '',
49 message: 'Username or E-mail',
50 });
51
52 password || questions.push({
53 name: 'password',
54 type: 'password',
55 message: 'Password',
56 });
57
58 let resource = new APIResource(host, port);
59
60 let setAccessToken = (accessToken, cb) => {
61
62 config.set('ACCESS_TOKEN', accessToken);
63 config.set('ACTIVE_LIBRARY_TOKEN', '');
64 config.unset('LIBRARY_TOKENS');
65 config.write();
66
67 console.log();
68 console.log(chalk.bold.green('Logged in successfully!') + ' Retrieving default Identity Token (API Key)...');
69
70 resource.authorize(config.get('ACCESS_TOKEN'));
71 resource.request('/v1/library_tokens').index({default: true}, (err, response) => {
72
73 if (err) {
74 return cb(err);
75 }
76
77 let tokens = (response && response.data) || [];
78
79 if (!tokens.length) {
80 console.log('Logged in, but could not retrieve default Identity Token.');
81 } else {
82 config.save('ACTIVE_LIBRARY_TOKEN', tokens[0].token);
83 console.log(`Active Identity Token (API Key) set to: ${chalk.bold(tokens[0].label)}`);
84 }
85
86 console.log();
87 return cb();
88
89 });
90 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected