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

Function authStatus

src/cli/handlers/auth.ts:253–340  ·  view source on GitHub ↗
(opts: {
  json?: boolean
  text?: boolean
})

Source from the content-addressed store, hash-verified

251}
252
253export async function authStatus(opts: {
254 json?: boolean
255 text?: boolean
256}): Promise<void> {
257 const { source: authTokenSource, hasToken } = getAuthTokenSource()
258 const { source: apiKeySource } = getAnthropicApiKeyWithSource()
259 const hasApiKeyEnvVar =
260 !!process.env.ANTHROPIC_API_KEY && !isRunningOnHomespace()
261 const oauthAccount = getOauthAccountInfo()
262 const subscriptionType = getSubscriptionType()
263 const using3P = isUsing3PServices()
264 const loggedIn =
265 hasToken || apiKeySource !== 'none' || hasApiKeyEnvVar || using3P
266
267 // Determine auth method
268 let authMethod: string = 'none'
269 if (using3P) {
270 authMethod = 'third_party'
271 } else if (authTokenSource === 'claude.ai') {
272 authMethod = 'claude.ai'
273 } else if (authTokenSource === 'apiKeyHelper') {
274 authMethod = 'api_key_helper'
275 } else if (authTokenSource !== 'none') {
276 authMethod = 'oauth_token'
277 } else if (apiKeySource === 'ANTHROPIC_API_KEY' || hasApiKeyEnvVar) {
278 authMethod = 'api_key'
279 } else if (apiKeySource === '/login managed key') {
280 authMethod = 'claude.ai'
281 }
282
283 if (opts.text) {
284 const properties = [
285 ...buildAccountProperties(),
286 ...buildAPIProviderProperties(),
287 ]
288 let hasAuthProperty = false
289 for (const prop of properties) {
290 const value =
291 typeof prop.value === 'string'
292 ? prop.value
293 : Array.isArray(prop.value)
294 ? prop.value.join(', ')
295 : null
296 if (value === null || value === 'none') {
297 continue
298 }
299 hasAuthProperty = true
300 if (prop.label) {
301 process.stdout.write(`${prop.label}: ${value}\n`)
302 } else {
303 process.stdout.write(`${value}\n`)
304 }
305 }
306 if (!hasAuthProperty && hasApiKeyEnvVar) {
307 process.stdout.write('API key: ANTHROPIC_API_KEY\n')
308 }
309 if (!loggedIn) {
310 process.stdout.write(

Callers 1

runFunction · 0.85

Calls 11

getAuthTokenSourceFunction · 0.85
isRunningOnHomespaceFunction · 0.85
getSubscriptionTypeFunction · 0.85
isUsing3PServicesFunction · 0.85
buildAccountPropertiesFunction · 0.85
getAPIProviderFunction · 0.85
jsonStringifyFunction · 0.85
getOauthAccountInfoFunction · 0.50
writeMethod · 0.45

Tested by

no test coverage detected