fix(auth): refresh token before API calls

This commit is contained in:
Brad Stein 2026-01-03 06:47:20 -03:00
parent 960e2c4c8a
commit c9ffcedceb
2 changed files with 12 additions and 0 deletions

4
.gitignore vendored
View File

@ -12,3 +12,7 @@ frontend/dist/
.coverage
docs/*.md
AGENTS.md
# Local-only wallpapers (do not commit)
media/atlas_bg.jpg
media/titan-iac-bg.png

View File

@ -105,6 +105,14 @@ export async function logout() {
export async function authFetch(url, options = {}) {
const headers = new Headers(options.headers || {});
if (keycloak?.authenticated) {
try {
await keycloak.updateToken(30);
updateFromToken();
} catch {
// ignore refresh failures; the API will return 401 and the UI can prompt for login
}
}
if (auth.token) headers.set("Authorization", `Bearer ${auth.token}`);
return fetch(url, { ...options, headers });
}