fix: sidebar auth race — pass token in getPort response

The sidebar called tryConnect() → getPort → got {port, connected} but
NO token. All subsequent requests (SSE, chat poll) failed with 401.
The token only arrived later via the health broadcast, but by then
the SSE connection was already broken.

Fix: include authToken in the getPort response so the sidebar has
the token from its very first connection attempt.
This commit is contained in:
Garry Tan
2026-04-02 19:12:44 -07:00
parent f7d95848f2
commit 7aa3973564
2 changed files with 2 additions and 3 deletions
+1 -1
View File
@@ -270,7 +270,7 @@ chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
}
if (msg.type === 'getPort') {
sendResponse({ port: serverPort, connected: isConnected });
sendResponse({ port: serverPort, connected: isConnected, token: authToken });
return true;
}
+1 -2
View File
@@ -1396,8 +1396,7 @@ function tryConnect() {
chrome.runtime.sendMessage({ type: 'getPort' }, (resp) => {
if (resp && resp.port && resp.connected) {
const url = `http://127.0.0.1:${resp.port}`;
// Token arrives via health broadcast from background.js
updateConnection(url, null);
updateConnection(url, resp.token || null);
} else {
setTimeout(tryConnect, 2000);
}