Public Access
feat(auth): tell the user when the session expired
Every 401 from Auth or Core now goes through useSessionExpired: the login page says the session expired and returns to the last page after login. App no longer removes a token that only the browser clock calls expired, so a backend 401 is the one signal. A 403 on the profile now shows an error instead.
This commit is contained in:
1 parent
03259d0515
commit
d4c0f8d8f3
19 files changed
+351
-35
No files matched your search
@@ -12,6 +12,7 @@ import BacklogCard from '../components/BacklogCard.jsx';
|
||||
import GameCover from '../components/GameCover.jsx';
|
||||
import GameStatusBadge from '../components/GameStatusBadge.jsx';
|
||||
import {formatPlaytime} from '../utils/games.js';
|
||||
import useSessionExpired from '../hooks/useSessionExpired.js';
|
||||
|
||||
const formatUnlockedAt = (instant, locale) => {
|
||||
if (!instant) return '';
|
||||
@@ -26,6 +27,7 @@ export default function GameDetail() {
|
||||
const {t, i18n} = useTranslation();
|
||||
const {appid} = useParams();
|
||||
const navigate = useNavigate();
|
||||
const expireSession = useSessionExpired();
|
||||
|
||||
const [data, setData] = useState(null);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
@@ -51,8 +53,7 @@ export default function GameDetail() {
|
||||
});
|
||||
if (cancelled) return;
|
||||
if (response.status === 401) {
|
||||
localStorage.removeItem('tbp_jwt');
|
||||
navigate('/login');
|
||||
expireSession();
|
||||
return;
|
||||
}
|
||||
if (response.status === 404) {
|
||||
@@ -77,7 +78,7 @@ export default function GameDetail() {
|
||||
return () => {
|
||||
cancelled = true;
|
||||
};
|
||||
}, [appid, navigate, t]);
|
||||
}, [appid, navigate, expireSession, t]);
|
||||
|
||||
const sortedAchievements = useMemo(() => {
|
||||
if (!data?.achievements) return [];
|
||||
|
||||
Reference in new issue
Block a user