()
| 452 | * @returns The organization UUID or null if not authenticated |
| 453 | */ |
| 454 | export async function getOrganizationUUID(): Promise<string | null> { |
| 455 | // Check global config first to avoid unnecessary API call |
| 456 | const globalConfig = getGlobalConfig() |
| 457 | const orgUUID = globalConfig.oauthAccount?.organizationUuid |
| 458 | if (orgUUID) { |
| 459 | return orgUUID |
| 460 | } |
| 461 | |
| 462 | // Fall back to fetching from profile (requires user:profile scope) |
| 463 | const accessToken = getClaudeAIOAuthTokens()?.accessToken |
| 464 | if (accessToken === undefined || !hasProfileScope()) { |
| 465 | return null |
| 466 | } |
| 467 | const profile = await getOauthProfileFromOauthToken(accessToken) |
| 468 | const profileOrgUUID = profile?.organization?.uuid |
| 469 | if (!profileOrgUUID) { |
| 470 | return null |
| 471 | } |
| 472 | return profileOrgUUID |
| 473 | } |
| 474 | |
| 475 | /** |
| 476 | * Populate the OAuth account info if it has not already been cached in config. |
no test coverage detected