MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / chooseLoginProfileName

Function chooseLoginProfileName

apps/cli/src/main.ts:2439–2460  ·  view source on GitHub ↗
(
  store: CliServerConnectionStore,
  account: {
    readonly origin: string;
    readonly sub?: string;
    readonly org?: string;
    readonly email?: string;
  },
)

Source from the content-addressed store, hash-verified

2437// distinct profiles instead of clobbering each other (the way opencode keys
2438// accounts by email/url). A re-login to the same account reuses its profile.
2439const chooseLoginProfileName = (
2440 store: CliServerConnectionStore,
2441 account: {
2442 readonly origin: string;
2443 readonly sub?: string;
2444 readonly org?: string;
2445 readonly email?: string;
2446 },
2447): string => {
2448 const identity =
2449 account.sub && account.org ? `${account.origin}|${account.sub}|${account.org}` : null;
2450 if (identity) {
2451 const existing = store.profiles.find((p) => oauthAccountIdentity(p.connection) === identity);
2452 if (existing) return existing.name;
2453 }
2454 const base = sanitizeProfileName(account.email ?? account.sub ?? loginHostLabel(account.origin));
2455 if (!store.profiles.some((p) => p.name === base)) return base;
2456 for (let suffix = 2; ; suffix += 1) {
2457 const candidate = `${base}-${suffix}`;
2458 if (!store.profiles.some((p) => p.name === candidate)) return candidate;
2459 }
2460};
2461
2462/** Where `executor login` lands with no flags and no stored profiles. */
2463const DEFAULT_LOGIN_ORIGIN = "https://executor.sh";

Callers 1

main.tsFile · 0.85

Calls 3

oauthAccountIdentityFunction · 0.85
sanitizeProfileNameFunction · 0.85
loginHostLabelFunction · 0.85

Tested by

no test coverage detected