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

+4 -4
View File
@@ -19,6 +19,8 @@ import useSessionExpired from '../hooks/useSessionExpired.js';
import useSaveAppearance from '../hooks/useSaveAppearance.js';
import {usePreferences} from '../context/PreferencesContext.jsx';
import PageContainer from '../components/PageContainer.jsx';
import {apiFetch} from '../utils/api.js';
import {getToken} from '../utils/auth.js';
const formatUnlockedAt = (instant, locale) => {
if (!instant) return '';
@@ -43,8 +45,7 @@ export default function GameDetail() {
useEffect(() => {
let cancelled = false;
const token = localStorage.getItem('tbp_jwt');
if (!token) {
if (!getToken()) {
navigate('/login');
return;
}
@@ -53,9 +54,8 @@ export default function GameDetail() {
(async () => {
try {
const url = `${import.meta.env.VITE_CORE_API_URL}/api/library/games/${appid}`;
const response = await fetch(url, {
const response = await apiFetch(url, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json',
},
});