Auto-redirect to login on 401 API responses

When a session token expires, API calls return 401 but nothing caught
it — errors were shown as generic dialogs or swallowed. Now both
apiClient and streamingService detect 401 responses and clear auth
state, which causes App.tsx to render the login modal automatically.
This commit is contained in:
Viktor Barzin 2026-02-13 21:16:53 +00:00
parent 3acf8db7af
commit a1829957c1
No known key found for this signature in database
GPG key ID: 0EB088298288D958
4 changed files with 29 additions and 1 deletions

View file

@ -18,6 +18,8 @@ import { Button } from './components/ui/button';
import { Filter } from 'lucide-react';
import type { GeoJSONFeatureCollection, PropertyProperties, PropertyFeature, POI, POITravelFilter } from '@/types';
import { refreshListings, streamListingGeoJSON, fetchUserPOIs, type StreamingProgress } from '@/services';
import { setOnUnauthorized } from '@/services/apiClient';
import { clearPasskeyUser } from './auth/passkeyService';
import { poiMetricPropertyName, injectPoiMetricProperty } from '@/utils/poiUtils';
import { useTaskProgress } from '@/hooks/useTaskProgress';
@ -94,6 +96,13 @@ function App() {
}
}, []);
useEffect(() => {
setOnUnauthorized(() => {
clearPasskeyUser();
setUser(null);
});
}, []);
const handlePasskeyLogin = (passkeyUser: AuthUser) => {
setUser(passkeyUser);
};