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

Function ensureAuth

src/auth/setup.ts:27–62  ·  view source on GitHub ↗
(config: Config)

Source from the content-addressed store, hash-verified

25}
26
27export async function ensureAuth(config: Config): Promise<void> {
28 if (config.apiKey || config.fileApiKey) return;
29 if (await loadCredentials()) return;
30
31 const envKey = process.env.MINIMAX_API_KEY;
32 if (envKey) {
33 if (!isInteractive({ nonInteractive: config.nonInteractive })) {
34 return; // env key is enough; no prompt
35 }
36 const save = await promptConfirm({
37 message: `Found MINIMAX_API_KEY in environment (${maskToken(envKey)}). Save to config file?`,
38 });
39 if (save) {
40 await persistApiKey(config, envKey);
41 }
42 return;
43 }
44
45 if (!isInteractive({ nonInteractive: config.nonInteractive })) {
46 throw new CLIError(
47 'No credentials found.',
48 ExitCode.AUTH,
49 'Log in: mmx auth login\nPass directly: --api-key sk-xxxxx',
50 );
51 }
52
53 const choice = await pickAuthMethod();
54 if (choice === 'api-key') {
55 const input = await promptText({ message: 'Enter your MiniMax API key:' });
56 if (!input) throw new CLIError('API key is required.', ExitCode.AUTH);
57 await persistApiKey(config, input);
58 return;
59 }
60
61 await runOAuthLogin(choice === 'oauth-cn' ? 'cn' : 'global');
62}
63
64export async function pickAuthMethod(): Promise<AuthChoice['value']> {
65 const { select, isCancel } = await import('@clack/prompts');

Callers 1

mainFunction · 0.90

Calls 8

loadCredentialsFunction · 0.90
isInteractiveFunction · 0.90
promptConfirmFunction · 0.90
maskTokenFunction · 0.90
promptTextFunction · 0.90
persistApiKeyFunction · 0.85
pickAuthMethodFunction · 0.85
runOAuthLoginFunction · 0.85

Tested by

no test coverage detected