feat(nav): add header navigation and show Steam ID on dashboard

Header links to Dashboard, Library and Settings. The logo, the login page and
the landing page lead logged-in users to the dashboard. Expired tokens are
removed, and a 403 on the dashboard logs out. Remove the dev dummy token.
This commit is contained in:
lobo committed 2026-09-24 08:57:03 +02:00
1 parent 44e23de6d6
commit 8fa605aff0
8 files changed
+124 -23

No files matched your search

+26
View File
@@ -0,0 +1,26 @@
const TOKEN_KEY = 'tbp_jwt';
/**
* Only checks `exp`. The signature is checked by the backends.
*/
export function isTokenValid(token, nowMs = Date.now()) {
try {
const payload = token.split('.')[1].replace(/-/g, '+').replace(/_/g, '/');
const {exp} = JSON.parse(atob(payload));
return typeof exp === 'number' && exp * 1000 > nowMs;
} catch {
return false;
}
}
/**
* Returns the stored token, or null. Removes an expired token.
*/
export function getValidToken() {
const token = localStorage.getItem(TOKEN_KEY);
if (token && !isTokenValid(token)) {
localStorage.removeItem(TOKEN_KEY);
return null;
}
return token;
}