MCPcopy Index your code
hub / github.com/Microck/opencode-studio / loadAuthConfig

Function loadAuthConfig

server/index.js:2719–2771  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2717};
2718
2719function loadAuthConfig() {
2720 const paths = getPaths();
2721 const allAuthConfigs = [];
2722
2723 // Check all candidate directories for auth.json
2724 paths.candidates.forEach(p => {
2725 const ap = path.join(path.dirname(p), 'auth.json');
2726 if (fs.existsSync(ap)) {
2727 try {
2728 allAuthConfigs.push(JSON.parse(fs.readFileSync(ap, 'utf8')));
2729 } catch {}
2730 }
2731 });
2732
2733 // Also check current active directory if not in candidates
2734 if (paths.current) {
2735 const ap = path.join(path.dirname(paths.current), 'auth.json');
2736 if (fs.existsSync(ap)) {
2737 try {
2738 allAuthConfigs.push(JSON.parse(fs.readFileSync(ap, 'utf8')));
2739 } catch {}
2740 }
2741 }
2742
2743 if (allAuthConfigs.length === 0) return null;
2744
2745 // Merge all configs, later ones (priority) overwrite earlier ones
2746 const cfg = Object.assign({}, ...allAuthConfigs);
2747
2748 try {
2749 const activePlugin = getActiveGooglePlugin();
2750
2751 // Find if any google auth exists in any merged config
2752 const anyGoogleAuth = cfg.google || cfg['google.gemini'] || cfg['google.antigravity'];
2753
2754 if (anyGoogleAuth) {
2755 // Ensure all 3 keys have at least some valid google auth data
2756 const baseAuth = cfg.google || cfg['google.antigravity'] || cfg['google.gemini'];
2757 if (!cfg.google) cfg.google = { ...baseAuth };
2758 if (!cfg['google.antigravity']) cfg['google.antigravity'] = { ...baseAuth };
2759 if (!cfg['google.gemini']) cfg['google.gemini'] = { ...baseAuth };
2760 }
2761
2762 // Always ensure the main 'google' key reflects the active plugin if it exists
2763 if (activePlugin === 'antigravity' && cfg['google.antigravity']) {
2764 cfg.google = { ...cfg['google.antigravity'] };
2765 } else if (activePlugin === 'gemini' && cfg['google.gemini']) {
2766 cfg.google = { ...cfg['google.gemini'] };
2767 }
2768
2769 return cfg;
2770 } catch { return cfg; }
2771}
2772
2773const AUTH_PROFILES_DIR = path.join(HOME_DIR, '.config', 'opencode-studio', 'auth-profiles');
2774

Callers 4

index.jsFile · 0.85
importCurrentAuthToPoolFunction · 0.85
rotateAccountFunction · 0.85

Calls 2

getPathsFunction · 0.70
getActiveGooglePluginFunction · 0.70

Tested by

no test coverage detected