fix(sync): merge auth providers across all candidate files
readStoredAuthProvidersFromDisk() previously returned only the first successfully-parsed auth file, missing providers that existed only in fallback locations (e.g. github-copilot in ~/.pi/agent/auth.json when another provider was in ~/.fusion/agent/auth.json). Now iterates all candidates and merges entries with first-found-wins priority.
This commit is contained in:
@@ -4,15 +4,19 @@ import { ApiError } from "../api-error.js";
|
||||
import { getAuthFileCandidates, type StoredAuthProvider } from "../auth-paths.js";
|
||||
|
||||
export async function readStoredAuthProvidersFromDisk(): Promise<Record<string, StoredAuthProvider>> {
|
||||
const merged: Record<string, StoredAuthProvider> = {};
|
||||
for (const authJsonPath of getAuthFileCandidates()) {
|
||||
try {
|
||||
const authContent = await fsReadFile(authJsonPath, "utf-8");
|
||||
return JSON.parse(authContent) as Record<string, StoredAuthProvider>;
|
||||
const parsed = JSON.parse(authContent) as Record<string, StoredAuthProvider>;
|
||||
for (const [provider, credential] of Object.entries(parsed)) {
|
||||
merged[provider] ??= credential;
|
||||
}
|
||||
} catch {
|
||||
// Try next candidate.
|
||||
}
|
||||
}
|
||||
return {};
|
||||
return merged;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user