- Remove preflight and OAuth steps from onboarding flow - Clear both modelType and model settings on logout - Reload ModelPicker via key after successful CoStrict login instead of closing it - Pre-fetch and cache CoStrict models silently after login
90 lines
3.4 KiB
TypeScript
90 lines
3.4 KiB
TypeScript
import * as React from 'react';
|
|
import { clearTrustedDeviceTokenCache } from '../../bridge/trustedDevice.js';
|
|
import { Text } from '@anthropic/ink';
|
|
import { refreshGrowthBookAfterAuthChange } from '../../services/analytics/growthbook.js';
|
|
import { getGroveNoticeConfig, getGroveSettings } from '../../services/api/grove.js';
|
|
import { clearPolicyLimitsCache } from '../../services/policyLimits/index.js';
|
|
// flushTelemetry is loaded lazily to avoid pulling in ~1.1MB of OpenTelemetry at startup
|
|
import { clearRemoteManagedSettingsCache } from '../../services/remoteManagedSettings/index.js';
|
|
import { deleteCoStrictCredentials } from '../../costrict/provider/credentials.js';
|
|
import { clearModelCache } from '../../costrict/provider/models.js';
|
|
import { getClaudeAIOAuthTokens, removeApiKey } from '../../utils/auth.js';
|
|
import { clearBetasCaches } from '../../utils/betas.js';
|
|
import { saveGlobalConfig } from '../../utils/config.js';
|
|
import { gracefulShutdownSync } from '../../utils/gracefulShutdown.js';
|
|
import { getSecureStorage } from '../../utils/secureStorage/index.js';
|
|
import { updateSettingsForSource } from '../../utils/settings/settings.js';
|
|
import { clearToolSchemaCache } from '../../utils/toolSchemaCache.js';
|
|
import { resetUserCache } from '../../utils/user.js';
|
|
|
|
export async function performLogout({ clearOnboarding = false }): Promise<void> {
|
|
// Flush telemetry BEFORE clearing credentials to prevent org data leakage
|
|
const { flushTelemetry } = await import('../../utils/telemetry/instrumentation.js');
|
|
await flushTelemetry();
|
|
|
|
await removeApiKey();
|
|
|
|
// Wipe all secure storage data on logout
|
|
const secureStorage = getSecureStorage();
|
|
secureStorage.delete();
|
|
|
|
// Clear CoStrict credentials and model cache
|
|
await deleteCoStrictCredentials();
|
|
clearModelCache();
|
|
delete process.env.CLAUDE_CODE_USE_COSTRICT;
|
|
updateSettingsForSource('userSettings', { modelType: undefined, model: undefined } as any);
|
|
|
|
await clearAuthRelatedCaches();
|
|
saveGlobalConfig(current => {
|
|
const updated = { ...current };
|
|
if (clearOnboarding) {
|
|
updated.hasCompletedOnboarding = false;
|
|
updated.subscriptionNoticeCount = 0;
|
|
updated.hasAvailableSubscription = false;
|
|
if (updated.customApiKeyResponses?.approved) {
|
|
updated.customApiKeyResponses = {
|
|
...updated.customApiKeyResponses,
|
|
approved: [],
|
|
};
|
|
}
|
|
}
|
|
updated.oauthAccount = undefined;
|
|
return updated;
|
|
});
|
|
}
|
|
|
|
// clearing anything memoized that must be invalidated when user/session/auth changes
|
|
export async function clearAuthRelatedCaches(): Promise<void> {
|
|
// Clear the OAuth token cache
|
|
getClaudeAIOAuthTokens.cache?.clear?.();
|
|
clearTrustedDeviceTokenCache();
|
|
clearBetasCaches();
|
|
clearToolSchemaCache();
|
|
|
|
// Clear user data cache BEFORE GrowthBook refresh so it picks up fresh credentials
|
|
resetUserCache();
|
|
refreshGrowthBookAfterAuthChange();
|
|
|
|
// Clear Grove config cache
|
|
getGroveNoticeConfig.cache?.clear?.();
|
|
getGroveSettings.cache?.clear?.();
|
|
|
|
// Clear remotely managed settings cache
|
|
await clearRemoteManagedSettingsCache();
|
|
|
|
// Clear policy limits cache
|
|
await clearPolicyLimitsCache();
|
|
}
|
|
|
|
export async function call(): Promise<React.ReactNode> {
|
|
await performLogout({ clearOnboarding: true });
|
|
|
|
const message = <Text>Successfully logged out from your CoStrict account.</Text>;
|
|
|
|
setTimeout(() => {
|
|
gracefulShutdownSync(0, 'logout');
|
|
}, 200);
|
|
|
|
return message;
|
|
}
|