MCPcopy Index your code
hub / github.com/upstash/context7 / getValidAccessToken

Function getValidAccessToken

packages/cli/src/utils/auth.ts:112–131  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

110 * expire and skip the refresh path entirely.
111 */
112export async function getValidAccessToken(): Promise<string | null> {
113 const tokens = loadTokens();
114 if (!tokens) return null;
115
116 if (!isTokenExpired(tokens)) {
117 return tokens.access_token;
118 }
119
120 if (!tokens.refresh_token) {
121 return null;
122 }
123
124 try {
125 const newTokens = await refreshAccessToken(tokens.refresh_token);
126 saveTokens(newTokens);
127 return newTokens.access_token;
128 } catch {
129 return null;
130 }
131}
132
133interface TokenErrorResponse {
134 error?: string;

Callers 5

loginCommandFunction · 0.85
whoamiCommandFunction · 0.85
resolveCliAuthFunction · 0.85
auth-utils.test.tsFile · 0.85

Calls 4

loadTokensFunction · 0.85
isTokenExpiredFunction · 0.85
refreshAccessTokenFunction · 0.85
saveTokensFunction · 0.85

Tested by

no test coverage detected