(
store: CliServerConnectionStore,
account: {
readonly origin: string;
readonly sub?: string;
readonly org?: string;
readonly email?: string;
},
)
| 2303 | // distinct profiles instead of clobbering each other (the way opencode keys |
| 2304 | // accounts by email/url). A re-login to the same account reuses its profile. |
| 2305 | const chooseLoginProfileName = ( |
| 2306 | store: CliServerConnectionStore, |
| 2307 | account: { |
| 2308 | readonly origin: string; |
| 2309 | readonly sub?: string; |
| 2310 | readonly org?: string; |
| 2311 | readonly email?: string; |
| 2312 | }, |
| 2313 | ): string => { |
| 2314 | const identity = |
| 2315 | account.sub && account.org ? `${account.origin}|${account.sub}|${account.org}` : null; |
| 2316 | if (identity) { |
| 2317 | const existing = store.profiles.find((p) => oauthAccountIdentity(p.connection) === identity); |
| 2318 | if (existing) return existing.name; |
| 2319 | } |
| 2320 | const base = sanitizeProfileName(account.email ?? account.sub ?? loginHostLabel(account.origin)); |
| 2321 | if (!store.profiles.some((p) => p.name === base)) return base; |
| 2322 | for (let suffix = 2; ; suffix += 1) { |
| 2323 | const candidate = `${base}-${suffix}`; |
| 2324 | if (!store.profiles.some((p) => p.name === candidate)) return candidate; |
| 2325 | } |
| 2326 | }; |
| 2327 | |
| 2328 | /** Where `executor login` lands with no flags and no stored profiles. */ |
| 2329 | const DEFAULT_LOGIN_ORIGIN = "https://executor.sh"; |
no test coverage detected