MCPcopy
hub / github.com/upstash/context7 / saveTokens

Function saveTokens

packages/cli/src/utils/auth.ts:34–46  ·  view source on GitHub ↗
(tokens: TokenData)

Source from the content-addressed store, hash-verified

32const CREDENTIALS_MODE = 0o600;
33
34export function saveTokens(tokens: TokenData): void {
35 const credentialsFile = getCredentialsFilePath();
36 migrateLegacyFileSync(CREDENTIALS_FILE_NAME, credentialsFile, CREDENTIALS_MODE);
37 ensureConfigDir();
38 const data = {
39 ...tokens,
40 expires_at:
41 tokens.expires_at ?? (tokens.expires_in ? Date.now() + tokens.expires_in * 1000 : undefined),
42 };
43 fs.writeFileSync(credentialsFile, JSON.stringify(data, null, 2), { mode: CREDENTIALS_MODE });
44 // `mode` is ignored when the file already exists; enforce it explicitly.
45 fs.chmodSync(credentialsFile, CREDENTIALS_MODE);
46}
47
48export function loadTokens(): TokenData | null {
49 const credentialsFile = resolveReadPathSync(

Callers 4

getValidAccessTokenFunction · 0.85
performLoginFunction · 0.85
resolveCliAuthFunction · 0.85
auth-utils.test.tsFile · 0.85

Calls 3

getCredentialsFilePathFunction · 0.85
migrateLegacyFileSyncFunction · 0.85
ensureConfigDirFunction · 0.85

Tested by

no test coverage detected