Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Improve login and whoami session details (#3044)

Rahul Tarakc5cc8e72eb64
diff --git a/ts/packages/cli/src/commands/index.ts b/ts/packages/cli/src/commands/index.ts
index a25fd7a3e..f85e8ab95 100644
--- a/ts/packages/cli/src/commands/index.ts
+++ b/ts/packages/cli/src/commands/index.ts
@@ -188,7 +188,9 @@ const normalizeHiddenDebugFlags = (argv: ReadonlyArray<string>): ReadonlyArray<s
const isRootHelp = (argv: ReadonlyArray<string>): boolean => {
const args = argv.slice(2);
- return args.length === 1 && (args[0] === '--help' || args[0] === '-h');
+ return (
+ args.length === 0 || (args.length === 1 && (args[0] === '--help' || args[0] === '-h'))
+ );
};
const isGenerateGraph = (argv: ReadonlyArray<string>): boolean => {
diff --git a/ts/packages/cli/src/commands/login.cmd.ts b/ts/packages/cli/src/commands/login.cmd.ts
index 6bf851a7e..ec627d356 100644
--- a/ts/packages/cli/src/commands/login.cmd.ts
+++ b/ts/packages/cli/src/commands/login.cmd.ts
@@ -42,6 +42,23 @@ const noSkillInstall = Options.boolean('no-skill-install').pipe(
Options.withDescription('Skip installing the composio-cli skill for Claude Code')
);
+const formatLoginSuccessMessage = (params: {
+ email?: string;
+ orgName?: string;
+}): string => {
+ const { email, orgName } = params;
+ if (email && orgName) {
+ return `Logged in as ${email} in "${orgName}"`;
+ }
+ if (email) {
+ return `Logged in as ${email}`;
+ }
+ if (orgName) {
+ return `Logged in successfully in "${orgName}"`;
+ }
+ return 'Logged in successfully';
+};
+
/**
* Verifies credentials via session/info and stores them.
*
@@ -117,7 +134,8 @@ const storeCredentials = (params: {
});
const email = sessionInfo?.org_member.email || fallbackEmail || undefined;
- yield* ui.log.success(email ? `Logged in as ${email}` : 'Logged in successfully');
+ const orgName = sessionInfo?.project.org.name || undefined;
+ yield* ui.log.success(formatLoginSuccessMessage({ email, orgName }));
if (!skipHints) {
yield* ui.log.info(commandHintStep('Execute a tool directly', 'root.execute'));
yield* ui.log.info(commandHintStep('Switch your default org', 'root.orgs.switch'));
@@ -240,7 +258,12 @@ const loginWithKey = (params: { key: string; noWait: boolean; skipOrgProjectPick
yield* primeConsumerConnectedToolkitsCacheInBackground({
orgId: result.id,
});
- yield* ui.log.success(`Default org set to "${result.name}".`);
+ yield* ui.log.success(
+ formatLoginSuccessMessage({
+ email: uakSessionInfo.org_member.email || linkedSession.account.email || undefined,
+ orgName: result.name,
+ })
+ );
}
const finalOrgId = result?.id ?? xOrgId;
const finalOrgName = result?.name ?? uakSessionInfo.project.org.name ?? '';
@@ -400,7 +423,12 @@ export const browserLogin = (params: {
yield* primeConsumerConnectedToolkitsCacheInBackground({
orgId: result.id,
});
- yield* ui.log.success(`Default org set to "${result.name}".`);
+ yield* ui.log.success(
+ formatLoginSuccessMessage({
+ email: uakSessionInfo.org_member.email || linkedSession.account.email || undefined,
+ orgName: result.name,
+ })
+ );
}
const finalOrgId = result?.id ?? xOrgId;
const finalOrgName = result?.name ?? uakSessionInfo.project.org.name ?? '';
diff --git a/ts/packages/cli/src/commands/whoami.cmd.ts b/ts/packages/cli/src/commands/whoami.cmd.ts
index 237cc2e6c..2614fcdb6 100644
--- a/ts/packages/cli/src/commands/whoami.cmd.ts
+++ b/ts/packages/cli/src/commands/whoami.cmd.ts
@@ -1,5 +1,6 @@
import { Command } from '@effect/cli';
import { Effect, Option } from 'effect';
+import { getSessionInfoByUserApiKey } from 'src/services/composio-clients';
import { ComposioUserContext } from 'src/services/user-context';
import { TerminalUI } from 'src/services/terminal-ui';
import { commandHintStep } from 'src/services/command-hints';
@@ -23,13 +24,25 @@ export const whoamiCmd = Command.make('whoami', {}).pipe(
yield* ctx.data.apiKey.pipe(
Option.match({
onNone: () => ui.log.warn('You are not logged in yet. Please run `composio login`.'),
- onSome: () =>
+ onSome: apiKey =>
Effect.gen(function* () {
const defaultOrgId = Option.getOrUndefined(ctx.data.orgId);
const testUserId = Option.getOrUndefined(ctx.data.testUserId);
+ const sessionInfo = yield* getSessionInfoByUserApiKey({
+ baseURL: ctx.data.baseURL,
+ userApiKey: apiKey,
+ }).pipe(Effect.option);
+ const email = Option.map(sessionInfo, info => info.org_member.email).pipe(
+ Option.getOrUndefined
+ );
+ const orgName = Option.map(sessionInfo, info => info.project.org.name).pipe(
+ Option.getOrUndefined
+ );
yield* ui.note(
[
+ `Email: ${email ?? 'unknown'}`,
+ `Default Org: ${orgName ?? 'unknown'}`,
`Default Org ID: ${defaultOrgId ?? 'not set'}`,
`Test User ID: ${testUserId ?? 'not set'}`,
].join('\n'),
@@ -43,6 +56,8 @@ export const whoamiCmd = Command.make('whoami', {}).pipe(
);
yield* ui.output(
JSON.stringify({
+ email: email ?? null,
+ default_org_name: orgName ?? null,
default_org_id: defaultOrgId ?? null,
test_user_id: testUserId ?? null,
})
diff --git a/ts/packages/cli/test/src/commands/$default.cmd.test.ts b/ts/packages/cli/test/src/commands/$default.cmd.test.ts
index 52008c87d..3773638a6 100644
--- a/ts/packages/cli/test/src/commands/$default.cmd.test.ts
+++ b/ts/packages/cli/test/src/commands/$default.cmd.test.ts
@@ -39,6 +39,18 @@ describe('CLI: composio', () => {
);
});
+ layer(TestLive())(it => {
+ it.scoped('[Given] no args [Then] prints help message', () =>
+ Effect.gen(function* () {
+ yield* cli([]);
+ const lines = yield* MockConsole.getLines({ stripAnsi: true });
+ const output = lines.join('\n');
+ expect(output).toContain('Usage:');
+ expect(output).toContain('composio');
+ })
+ );
+ });
+
layer(TestLive())(it => {
it.scoped('[Given] --help flag [Then] prints help message', () =>
Effect.gen(function* () {
diff --git a/ts/packages/cli/test/src/commands/whoami.cmd.test.ts b/ts/packages/cli/test/src/commands/whoami.cmd.test.ts
index b2820e0f9..fd1086d3e 100644
--- a/ts/packages/cli/test/src/commands/whoami.cmd.test.ts
+++ b/ts/packages/cli/test/src/commands/whoami.cmd.test.ts
@@ -2,8 +2,13 @@ import { describe, expect, layer } from '@effect/vitest';
import { ConfigProvider, Effect } from 'effect';
import { extendConfigProvider } from 'src/services/config';
import { cli, TestLive, MockConsole } from 'test/__utils__';
+import { afterEach, vi } from 'vitest';
describe('CLI: composio whoami', () => {
+ afterEach(() => {
+ vi.restoreAllMocks();
+ });
+
const testConfigProvider = ConfigProvider.fromMap(
new Map([['COMPOSIO_USER_API_KEY', 'api_key_from_test_config_provider']])
).pipe(extendConfigProvider);
@@ -18,6 +23,8 @@ describe('CLI: composio whoami', () => {
const output = lines.join('\n');
expect(output).not.toContain(`api_key_from_test_config_provider`);
expect(output).not.toContain(`global_user_api_key`);
+ expect(output).toContain(`"email":null`);
+ expect(output).toContain(`"default_org_name":null`);
expect(output).toContain(`"default_org_id":null`);
expect(output).toContain(`"test_user_id":null`);
})
@@ -34,9 +41,57 @@ describe('CLI: composio whoami', () => {
const output = lines.join('\n');
expect(output).not.toContain(`api_key_from_test_fixture`);
expect(output).not.toContain(`global_user_api_key`);
+ expect(output).toContain(`"email":null`);
+ expect(output).toContain(`"default_org_name":null`);
expect(output).toContain(`"default_org_id":null`);
expect(output).toContain(`"test_user_id":null`);
})
);
});
+
+ layer(TestLive({ baseConfigProvider: testConfigProvider }))('with session info', it => {
+ it.scoped('[Given] session info is available [Then] prints email and org name', () =>
+ Effect.gen(function* () {
+ vi.spyOn(globalThis, 'fetch').mockResolvedValue(
+ new Response(
+ JSON.stringify({
+ project: {
+ name: 'Test Project',
+ id: 'proj_123',
+ org_id: 'org_123',
+ nano_id: 'proj_nano_123',
+ email: '[email protected]',
+ created_at: '2026-03-27T00:00:00.000Z',
+ updated_at: '2026-03-27T00:00:00.000Z',
+ org: {
+ name: 'Acme Org',
+ id: 'org_123',
+ plan: 'enterprise',
+ },
+ },
+ org_member: {
+ id: 'om_123',
+ user_id: 'usr_123',
+ email: '[email protected]',
+ name: 'Test Person',
+ role: 'admin',
+ },
+ api_key: null,
+ }),
+ {
+ status: 200,
+ headers: { 'Content-Type': 'application/json' },
+ }
+ )
+ );
+
+ yield* cli(['whoami']);
+
+ const lines = yield* MockConsole.getLines();
+ const output = lines.join('\n');
+ expect(output).toContain(`"email":"[email protected]"`);
+ expect(output).toContain(`"default_org_name":"Acme Org"`);
+ })
+ );
+ });
});