fix(desktop): implement bearer token auth for windows webview2
Release Desktop Apps / build-linux (push) Successful in 2m49s
Release Desktop Apps / release (push) Has been cancelled
Release Desktop Apps / build-windows (push) Has been cancelled

This commit is contained in:
2026-07-16 14:30:28 -04:00
parent f4f6e8560b
commit 92be2a30d1
2 changed files with 43 additions and 10 deletions
+3 -6
View File
@@ -61,13 +61,10 @@ jobs:
rustc --version
shell: cmd
- name: Cache Rust target and registry
uses: actions/cache@v3
uses: Swatinem/rust-cache@v2
with:
path: |
~/.cargo/registry
~/.cargo/git
web/src-tauri/target
key: ${{ runner.os }}-cargo-${{ hashFiles('web/src-tauri/Cargo.lock') }}
workspaces: |
web/src-tauri
- name: Build frontend
run: cd web && npm ci && npm run build
shell: cmd
+40 -4
View File
@@ -8,12 +8,37 @@ if (isTauri) {
const TARGET = 'https://dumpster.dustin.coffee';
const WS_TARGET = 'wss://dumpster.dustin.coffee';
let sessionToken = localStorage.getItem('dumpster_session_token') || '';
const originalFetch = window.fetch;
window.fetch = async (input, init) => {
if (typeof input === 'string' && input.startsWith('/')) {
input = TARGET + input;
let url = typeof input === 'string' ? input : input.toString();
if (url.startsWith('/')) {
url = TARGET + url;
}
return originalFetch(input, init);
let newInit = init ? { ...init } : {};
if (sessionToken) {
newInit.headers = {
...newInit.headers,
'Authorization': 'Bearer ' + sessionToken
};
}
const response = await originalFetch(url, newInit);
const token = response.headers.get('X-Session-Token');
if (token) {
sessionToken = token;
localStorage.setItem('dumpster_session_token', token);
}
if (url.endsWith('/auth/logout') && response.ok) {
sessionToken = '';
localStorage.removeItem('dumpster_session_token');
}
return response;
};
const OriginalWebSocket = window.WebSocket;
@@ -27,7 +52,18 @@ if (isTauri) {
} else if (urlStr.startsWith('/')) {
urlStr = WS_TARGET + urlStr;
}
return new OriginalWebSocket(urlStr, protocols);
const ws = new OriginalWebSocket(urlStr, protocols);
if (sessionToken && urlStr.includes('/ws') && !urlStr.includes('/ws/bot')) {
const originalOnOpen = ws.onopen;
ws.onopen = function(ev) {
ws.send(JSON.stringify({ token: sessionToken }));
if (originalOnOpen) originalOnOpen.call(ws, ev);
};
}
return ws;
} as unknown as typeof WebSocket;
window.WebSocket.prototype = OriginalWebSocket.prototype;
}