MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / clearOAuth

Function clearOAuth

packages/cli/src/auth/store.ts:195–214  ·  view source on GitHub ↗
(path = credentialPath())

Source from the content-addressed store, hash-verified

193
194/** Remove only the `oauth` block. Used by `auth logout --keep-api-key`. */
195export async function clearOAuth(path = credentialPath()): Promise<void> {
196 const { credentials, source } = await readStore(path);
197 if (source === "absent" || !credentials.oauth) return;
198 // Drop oauth, keep everything else (api_key, the friendly-display
199 // user block, and any unknown/foreign keys) so a logout that only
200 // clears the OAuth session doesn't silently wipe co-located data.
201 const next: Credentials = { ...credentials };
202 delete next.oauth;
203 if (!next.api_key && !hasPreservedUnknownData(next)) {
204 // Nothing worth preserving survives. The leftover user block had no
205 // friendly fields and there's no foreign/unknown data to round-trip,
206 // so this is orphaned metadata with no credential to attach to — drop
207 // the file. (A surviving top-level / user-block unknown key, by
208 // contrast, may be a future credential another CLI owns, so we keep
209 // the file in that case.)
210 await deleteStore(path);
211 return;
212 }
213 await writeStore(next, path);
214}
215
216async function ensureDir(dir: string): Promise<void> {
217 try {

Callers 2

store.test.tsFile · 0.85
runFunction · 0.85

Calls 5

credentialPathFunction · 0.85
readStoreFunction · 0.85
hasPreservedUnknownDataFunction · 0.85
deleteStoreFunction · 0.85
writeStoreFunction · 0.85

Tested by

no test coverage detected