()
| 424 | * @returns The organization UUID or null if not authenticated |
| 425 | */ |
| 426 | export async function getOrganizationUUID(): Promise<string | null> { |
| 427 | // Check global config first to avoid unnecessary API call |
| 428 | const globalConfig = getGlobalConfig() |
| 429 | const orgUUID = globalConfig.oauthAccount?.organizationUuid |
| 430 | if (orgUUID) { |
| 431 | return orgUUID |
| 432 | } |
| 433 | |
| 434 | // Fall back to fetching from profile (requires user:profile scope) |
| 435 | const accessToken = getClaudeAIOAuthTokens()?.accessToken |
| 436 | if (accessToken === undefined || !hasProfileScope()) { |
| 437 | return null |
| 438 | } |
| 439 | const profile = await getOauthProfileFromOauthToken(accessToken) |
| 440 | const profileOrgUUID = profile?.organization?.uuid |
| 441 | if (!profileOrgUUID) { |
| 442 | return null |
| 443 | } |
| 444 | return profileOrgUUID |
| 445 | } |
| 446 | |
| 447 | /** |
| 448 | * Populate the OAuth account info if it has not already been cached in config. |
no test coverage detected