MCPcopy Create free account
hub / github.com/freecodexyz/free-code / wouldLoseAuthState

Function wouldLoseAuthState

src/utils/config.ts:803–815  ·  view source on GitHub ↗

* Detect whether writing `fresh` would lose auth/onboarding state that the * in-memory cache still has. This happens when `getConfig` hits a corrupted * or truncated file mid-write (from another process or a non-atomic fallback) * and returns DEFAULT_GLOBAL_CONFIG. Writing that back would permane

(fresh: {
  oauthAccount?: unknown
  hasCompletedOnboarding?: boolean
})

Source from the content-addressed store, hash-verified

801 * wipe auth. See GH #3117.
802 */
803function wouldLoseAuthState(fresh: {
804 oauthAccount?: unknown
805 hasCompletedOnboarding?: boolean
806}): boolean {
807 const cached = globalConfigCache.config
808 if (!cached) return false
809 const lostOauth =
810 cached.oauthAccount !== undefined && fresh.oauthAccount === undefined
811 const lostOnboarding =
812 cached.hasCompletedOnboarding === true &&
813 fresh.hasCompletedOnboarding !== true
814 return lostOauth || lostOnboarding
815}
816
817export function saveGlobalConfig(
818 updater: (currentConfig: GlobalConfig) => GlobalConfig,

Callers 3

saveGlobalConfigFunction · 0.85
saveConfigWithLockFunction · 0.85
saveCurrentProjectConfigFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected