MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / AppWithAsyncAuth

Function AppWithAsyncAuth

cli/src/index.tsx:362–447  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

360 const queryClient = createQueryClient()
361
362 const AppWithAsyncAuth = () => {
363 const [requireAuth, setRequireAuth] = React.useState<boolean | null>(null)
364 const [hasInvalidCredentials, setHasInvalidCredentials] =
365 React.useState(false)
366 const [fileTree, setFileTree] = React.useState<FileTreeNode[]>([])
367 const [currentProjectRoot, setCurrentProjectRoot] =
368 React.useState(projectRoot)
369 const [showProjectPickerScreen, setShowProjectPickerScreen] =
370 React.useState(showProjectPicker)
371
372 React.useEffect(() => {
373 const apiKey = getAuthTokenDetails().token ?? ''
374
375 if (!apiKey) {
376 setRequireAuth(true)
377 setHasInvalidCredentials(false)
378 return
379 }
380
381 setHasInvalidCredentials(true)
382 setRequireAuth(false)
383 }, [])
384
385 const loadFileTree = React.useCallback(async (root: string) => {
386 try {
387 if (root) {
388 const tree = await getProjectFileTree({
389 projectRoot: root,
390 fs: fs.promises,
391 })
392 setFileTree(tree)
393 }
394 } catch (error) {
395 // Silently fail - fileTree is optional for @ menu
396 }
397 }, [])
398
399 React.useEffect(() => {
400 loadFileTree(currentProjectRoot)
401 }, [currentProjectRoot, loadFileTree])
402
403 // Callback for when user selects a new project from the picker
404 const handleProjectChange = React.useCallback(
405 async (newProjectPath: string) => {
406 // Change process working directory
407 process.chdir(newProjectPath)
408
409 // Track directory change (avoid logging full paths for privacy)
410 const isGitRepo = fs.existsSync(path.join(newProjectPath, '.git'))
411 const pathDepth = newProjectPath.split(path.sep).filter(Boolean).length
412 trackEvent(AnalyticsEvent.CHANGE_DIRECTORY, {
413 isGitRepo,
414 pathDepth,
415 isHomeDir: newProjectPath === os.homedir(),
416 })
417 // Update the project root in the module state
418 setProjectRoot(newProjectPath)
419 // Reset client to ensure tools use the updated project root

Callers

nothing calls this directly

Calls 6

getAuthTokenDetailsFunction · 0.90
getProjectFileTreeFunction · 0.90
trackEventFunction · 0.90
setProjectRootFunction · 0.90
resetCodebuffClientFunction · 0.90
saveRecentProjectFunction · 0.90

Tested by

no test coverage detected