({
clearOnboarding = false
})
| 14 | import { clearToolSchemaCache } from '../../utils/toolSchemaCache.js'; |
| 15 | import { resetUserCache } from '../../utils/user.js'; |
| 16 | export async function performLogout({ |
| 17 | clearOnboarding = false |
| 18 | }): Promise<void> { |
| 19 | // Flush telemetry BEFORE clearing credentials to prevent org data leakage |
| 20 | const { |
| 21 | flushTelemetry |
| 22 | } = await import('../../utils/telemetry/instrumentation.js'); |
| 23 | await flushTelemetry(); |
| 24 | await removeApiKey(); |
| 25 | |
| 26 | // Wipe all secure storage data on logout |
| 27 | const secureStorage = getSecureStorage(); |
| 28 | secureStorage.delete(); |
| 29 | await clearAuthRelatedCaches(); |
| 30 | saveGlobalConfig(current => { |
| 31 | const updated = { |
| 32 | ...current |
| 33 | }; |
| 34 | if (clearOnboarding) { |
| 35 | updated.hasCompletedOnboarding = false; |
| 36 | updated.subscriptionNoticeCount = 0; |
| 37 | updated.hasAvailableSubscription = false; |
| 38 | if (updated.customApiKeyResponses?.approved) { |
| 39 | updated.customApiKeyResponses = { |
| 40 | ...updated.customApiKeyResponses, |
| 41 | approved: [] |
| 42 | }; |
| 43 | } |
| 44 | } |
| 45 | updated.oauthAccount = undefined; |
| 46 | return updated; |
| 47 | }); |
| 48 | } |
| 49 | |
| 50 | // clearing anything memoized that must be invalidated when user/session/auth changes |
| 51 | export async function clearAuthRelatedCaches(): Promise<void> { |
no test coverage detected