MCPcopy
hub / github.com/MiniMax-AI/cli / run

Function run

src/commands/auth/login.ts:59–118  ·  view source on GitHub ↗
(config: Config, flags: GlobalFlags)

Source from the content-addressed store, hash-verified

57 'mmx auth login --recommend --region=cn',
58 ],
59 async run(config: Config, flags: GlobalFlags) {
60 const envKey = process.env.MINIMAX_API_KEY;
61 if (envKey && !flags.apiKey) {
62 const masked = maskToken(envKey);
63 if (isInteractive({ nonInteractive: config.nonInteractive })) {
64 const { confirm, isCancel } = await import('@clack/prompts');
65 const proceed = await confirm({
66 message: `MINIMAX_API_KEY is set (${masked}). Configure persistent credentials anyway?`,
67 initialValue: false,
68 });
69 if (isCancel(proceed) || !proceed) {
70 process.stdout.write('Login skipped. Using environment variable.\n');
71 process.exit(0);
72 }
73 } else {
74 process.stderr.write(`Warning: MINIMAX_API_KEY is already set in environment.\n`);
75 }
76 }
77
78 if (flags.apiKey) {
79 await loginWithApiKey(config, flags.apiKey as string);
80 return;
81 }
82
83 if (config.dryRun) {
84 console.log('Would prompt for auth method (oauth-global, oauth-cn, api-key).');
85 return;
86 }
87
88 if (!isInteractive({ nonInteractive: config.nonInteractive })) {
89 throw new CLIError(
90 '--api-key is required in non-interactive mode.',
91 ExitCode.USAGE,
92 'mmx auth login --api-key sk-xxxxx',
93 );
94 }
95
96 // --recommend: skip the 3-option menu, go straight to OAuth.
97 // With --region, skip the region picker too.
98 if (flags.recommend) {
99 const region = (flags.region as Region) || await pickOAuthRegion();
100 await completeOAuthLogin(config, region);
101 return;
102 }
103
104 const choice = await pickAuthMethod();
105 if (choice === 'api-key') {
106 const { text, isCancel } = await import('@clack/prompts');
107 const key = await text({
108 message: 'Paste your MiniMax API key:',
109 validate: (v) => (v && v.length > 0 ? undefined : 'API key cannot be empty.'),
110 });
111 if (isCancel(key)) throw new CLIError('Authentication cancelled.', ExitCode.AUTH);
112 await loginWithApiKey(config, key as string);
113 return;
114 }
115
116 const region: Region = (flags.region as Region) || (choice === 'oauth-cn' ? 'cn' : 'global');

Callers

nothing calls this directly

Calls 6

maskTokenFunction · 0.90
isInteractiveFunction · 0.90
pickOAuthRegionFunction · 0.90
pickAuthMethodFunction · 0.90
loginWithApiKeyFunction · 0.85
completeOAuthLoginFunction · 0.85

Tested by

no test coverage detected