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

Function chooseLoginProfileName

apps/cli/src/main.ts:2280–2301  ·  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

2278// distinct profiles instead of clobbering each other (the way opencode keys
2279// accounts by email/url). A re-login to the same account reuses its profile.
2280const chooseLoginProfileName = (
2281 store: CliServerConnectionStore,
2282 account: {
2283 readonly origin: string;
2284 readonly sub?: string;
2285 readonly org?: string;
2286 readonly email?: string;
2287 },
2288): string => {
2289 const identity =
2290 account.sub && account.org ? `${account.origin}|${account.sub}|${account.org}` : null;
2291 if (identity) {
2292 const existing = store.profiles.find((p) => oauthAccountIdentity(p.connection) === identity);
2293 if (existing) return existing.name;
2294 }
2295 const base = sanitizeProfileName(account.email ?? account.sub ?? loginHostLabel(account.origin));
2296 if (!store.profiles.some((p) => p.name === base)) return base;
2297 for (let suffix = 2; ; suffix += 1) {
2298 const candidate = `${base}-${suffix}`;
2299 if (!store.profiles.some((p) => p.name === candidate)) return candidate;
2300 }
2301};
2302
2303// Resolve which server a login/logout targets: an existing profile (--server
2304// or the default) or a bare origin (--base-url). The profile name is decided

Callers 1

main.tsFile · 0.85

Calls 3

oauthAccountIdentityFunction · 0.85
sanitizeProfileNameFunction · 0.85
loginHostLabelFunction · 0.85

Tested by

no test coverage detected