feat(auth): use the cookie session and refresh on 401

The token is no longer stored; a tbp_session flag remembers the
login. apiFetch renews the session once on a 401 and sends the
request again. Parallel requests and other tabs share one refresh,
because Auth revokes the session when a refresh token is used twice.
Only a 401 from the refresh ends the session; a 502 or no network
shows the normal error.
This commit is contained in:
lobo committed 2026-09-25 13:45:08 +02:00
1 parent 5ff8d48c53
commit d9a39dda22
34 files changed
+297 -147

No files matched your search

+5 -5
View File
@@ -23,7 +23,7 @@ import {ACCENTS, CORNERS} from '../utils/appearance.js';
import {coverUrl} from '../utils/games.js';
import {cn} from '@/lib/utils';
import {apiFetch} from '../utils/api.js';
import {getToken, setToken} from '../utils/auth.js';
import {hasSession, markSession} from '../utils/auth.js';
const BACKEND_ERROR_KEY = {
STEAM_ID_ALREADY_IN_USE: 'REGISTRATION.ERROR_STEAM_ID_IN_USE',
@@ -63,7 +63,7 @@ export default function SettingsPage() {
});
useEffect(() => {
if (!getToken()) {
if (!hasSession()) {
navigate('/login');
return;
}
@@ -107,7 +107,7 @@ export default function SettingsPage() {
}, [navigate, expireSession, reset, t]);
const persistSettings = async (payload) => {
if (!getToken()) {
if (!hasSession()) {
navigate('/login');
return {ok: false};
}
@@ -133,8 +133,8 @@ export default function SettingsPage() {
return {ok: false};
}
const data = await response.json();
setToken(data.token); // Core reads the steamId from the token
// Auth set a new access cookie for the new Steam ID; the new stamp makes the header load it again.
markSession();
toast.success(t('SETTINGS.SAVED'));
return {ok: true};
} catch (err) {