fix(auth): refresh token before API calls
This commit is contained in:
parent
960e2c4c8a
commit
c9ffcedceb
4
.gitignore
vendored
4
.gitignore
vendored
@ -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
|
||||
|
||||
@ -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 });
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user