Skip to content

Commit 65a8088

Browse files
Fix electron-updater auth for private GitHub repos
Use setFeedURL with private: true when a GitHub token is provided so electron-updater queries the GitHub API instead of the public Atom feed which rejects Bearer auth headers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cca1aa1 commit 65a8088

File tree

1 file changed

+34
-4
lines changed

1 file changed

+34
-4
lines changed

apps/desktop/src/main.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,28 @@ function resolveAppRoot(): string {
253253
return app.getAppPath();
254254
}
255255

256+
/** Read the baked-in app-update.yml config (if applicable). */
257+
function readAppUpdateYml(): Record<string, string> | null {
258+
try {
259+
// electron-updater reads from process.resourcesPath in packaged builds,
260+
// or dev-app-update.yml via app.getAppPath() in dev.
261+
const ymlPath = app.isPackaged
262+
? Path.join(process.resourcesPath, "app-update.yml")
263+
: Path.join(app.getAppPath(), "dev-app-update.yml");
264+
const raw = FS.readFileSync(ymlPath, "utf-8");
265+
// The YAML is simple key-value pairs — avoid pulling in a YAML parser by
266+
// doing a line-based parse (fields: provider, owner, repo, releaseType, …).
267+
const entries: Record<string, string> = {};
268+
for (const line of raw.split("\n")) {
269+
const match = line.match(/^(\w+):\s*(.+)$/);
270+
if (match?.[1] && match[2]) entries[match[1]] = match[2].trim();
271+
}
272+
return entries.provider ? entries : null;
273+
} catch {
274+
return null;
275+
}
276+
}
277+
256278
function normalizeCommitHash(value: unknown): string | null {
257279
if (typeof value !== "string") {
258280
return null;
@@ -687,10 +709,18 @@ function configureAutoUpdater(): void {
687709
process.env.GH_TOKEN?.trim() ||
688710
"";
689711
if (githubToken) {
690-
autoUpdater.requestHeaders = {
691-
...autoUpdater.requestHeaders,
692-
Authorization: `Bearer ${githubToken}`,
693-
};
712+
// When a token is provided, re-configure the feed with `private: true` so
713+
// electron-updater uses the GitHub API (api.github.com) instead of the
714+
// public Atom feed (github.com/…/releases.atom) which rejects Bearer auth.
715+
const appUpdateYml = readAppUpdateYml();
716+
if (appUpdateYml?.provider === "github") {
717+
autoUpdater.setFeedURL({
718+
...appUpdateYml,
719+
provider: "github" as const,
720+
private: true,
721+
token: githubToken,
722+
});
723+
}
694724
}
695725

696726
autoUpdater.autoDownload = false;

0 commit comments

Comments
 (0)