refactor(auth): send login token through apiFetch
Build, Test & Push Frontend / quality-check (push) Successful in 13s
Build, Test & Push Frontend / docker (push) Successful in 23s

All authenticated calls now use apiFetch, and only utils/auth.js
touches the stored token. The cookie login can then change these two
files instead of every page.
This commit is contained in:
lobo committed 2026-09-25 11:29:14 +02:00
1 parent 085fcf15a4
commit 5ff8d48c53
18 files changed
+127 -70

No files matched your search

+8 -2
View File
@@ -1,5 +1,11 @@
const TOKEN_KEY = 'tbp_jwt';
export const getToken = () => localStorage.getItem(TOKEN_KEY);
export const setToken = (token) => localStorage.setItem(TOKEN_KEY, token);
export const clearToken = () => localStorage.removeItem(TOKEN_KEY);
/**
* Only checks `exp`. The signature is checked by the backends.
*/
@@ -17,9 +23,9 @@ export function isTokenValid(token, nowMs = Date.now()) {
* Returns the stored token, or null. Removes an expired token.
*/
export function getValidToken() {
const token = localStorage.getItem(TOKEN_KEY);
const token = getToken();
if (token && !isTokenValid(token)) {
localStorage.removeItem(TOKEN_KEY);
clearToken();
return null;
}
return token;