MCPcopy Index your code
hub / github.com/callstack/agent-device / authCommand

Function authCommand

src/cli/commands/auth.ts:7–42  ·  view source on GitHub ↗
({ positionals, flags })

Source from the content-addressed store, hash-verified

5import type { ClientCommandHandler } from './router-types.ts';
6
7export const authCommand: ClientCommandHandler = async ({ positionals, flags }) => {
8 const subcommand = positionals[0] ?? 'status';
9 const stateDir = resolveDaemonPaths(flags.stateDir).baseDir;
10 if (subcommand === 'status') {
11 const status = summarizeCliSession({ stateDir });
12 writeCommandOutput(flags, status, () => renderAuthStatus(status));
13 return true;
14 }
15 if (subcommand === 'login') {
16 const login = await loginWithDeviceAuth({
17 stateDir,
18 flags,
19 commandLabel: 'agent-device auth login',
20 });
21 const data = {
22 authenticated: true,
23 source: 'cli-session',
24 sessionId: login.session.id,
25 cloudBaseUrl: login.session.cloudBaseUrl,
26 workspaceId: login.session.workspaceId,
27 accountId: login.session.accountId,
28 expiresAt: login.session.expiresAt,
29 agentTokenExpiresAt: login.expiresAt,
30 };
31 writeCommandOutput(flags, data, () => 'Authenticated with cloud CLI session.');
32 return true;
33 }
34 if (subcommand === 'logout') {
35 const removed = removeCliSession({ stateDir });
36 writeCommandOutput(flags, { authenticated: false, removed }, () =>
37 removed ? 'Removed stored cloud CLI session.' : 'No stored cloud CLI session.',
38 );
39 return true;
40 }
41 throw new AppError('INVALID_ARGS', 'auth accepts only: status, login, logout');
42};
43
44function renderAuthStatus(status: ReturnType<typeof summarizeCliSession>): string {
45 if (!status.authenticated) return 'Not authenticated.';

Callers

nothing calls this directly

Calls 6

resolveDaemonPathsFunction · 0.90
summarizeCliSessionFunction · 0.90
writeCommandOutputFunction · 0.90
loginWithDeviceAuthFunction · 0.90
removeCliSessionFunction · 0.90
renderAuthStatusFunction · 0.85

Tested by

no test coverage detected