Skip to content

Commit 7e02974

Browse files
committed
Fix loading the auth token
1 parent 028765a commit 7e02974

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

src/api/api.ts

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,30 @@ let cachedToken: string | null = null;
1212
function getGitHubToken(): string {
1313
if (cachedToken) return cachedToken;
1414
try {
15-
cachedToken = execSync("gh auth token", { encoding: "utf-8" }).trim();
15+
let token: string;
16+
17+
if (process.platform === "win32") {
18+
// Windows: gh should be in PATH from installer
19+
token = execSync("gh auth token", { encoding: "utf-8" }).trim();
20+
} else {
21+
// macOS/Linux: Use login shell to source user's profile for proper PATH
22+
// This ensures gh is found even when app is launched from Finder/desktop
23+
const shell = process.env.SHELL || "/bin/sh";
24+
token = execSync(`${shell} -l -c "gh auth token"`, {
25+
encoding: "utf-8",
26+
}).trim();
27+
}
28+
29+
cachedToken = token;
1630
return cachedToken;
1731
} catch (err) {
18-
throw new Error("Failed to get GitHub token. Make sure gh CLI is authenticated: "+ (err as Error).message, {
19-
cause: err,
20-
});
32+
throw new Error(
33+
"Failed to get GitHub token. Make sure gh CLI is authenticated: " +
34+
(err as Error).message,
35+
{
36+
cause: err,
37+
}
38+
);
2139
}
2240
}
2341

@@ -186,9 +204,9 @@ const api = new Hono()
186204
isResolved: thread.isResolved,
187205
resolvedBy: thread.resolvedBy
188206
? {
189-
login: thread.resolvedBy.login,
190-
avatar_url: thread.resolvedBy.avatarUrl,
191-
}
207+
login: thread.resolvedBy.login,
208+
avatar_url: thread.resolvedBy.avatarUrl,
209+
}
192210
: null,
193211
});
194212
}

0 commit comments

Comments
 (0)