Skip to content

Commit 33d52cf

Browse files
committed
demo video
1 parent 15d4461 commit 33d52cf

6 files changed

Lines changed: 17 additions & 133 deletions

File tree

client/README.md

Lines changed: 0 additions & 115 deletions
This file was deleted.

client/debug_catch_creation.py

Whitespace-only changes.

client/src/components/BackgroundWrapper.tsx

Whitespace-only changes.

client/src/contexts/AuthContext.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
2727

2828
useEffect(() => {
2929
loadStoredUser();
30+
// inject logout into ApiService when provider mounts
31+
ApiService.setUnauthorizedHandler(async () => {
32+
await logout();
33+
console.log('AuthContext (onUnauthorized): User logged out due to unauthorized access');
34+
});
3035
}, []);
3136

3237
const loadStoredUser = async () => {
@@ -168,3 +173,4 @@ export const useAuth = (): AuthContextType => {
168173
}
169174
return context;
170175
};
176+

client/src/screens/MapScreen.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,14 @@ import {
99
import LoadingSpinner from '../components/LoadingSpinner';
1010
import * as Location from 'expo-location';
1111
import { useAuth } from '../contexts/AuthContext';
12-
import { useFocusEffect, useNavigation } from '@react-navigation/native';
13-
import { NativeStackNavigationProp } from '@react-navigation/native-stack';
14-
import { RootStackParamList } from '../navigation/AppNavigator';
12+
import { useFocusEffect } from '@react-navigation/native';
1513
import ApiService from '../services/api';
1614
import { Pin } from '../types/api';
1715
import MapComponent from '../components/MapComponent';
1816

19-
type MapScreenNavigationProp = NativeStackNavigationProp<RootStackParamList, 'Map'>;
20-
2117
interface MapScreenProps {}
2218

2319
const MapScreen: React.FC<MapScreenProps> = () => {
24-
const navigation = useNavigation<MapScreenNavigationProp>();
2520
const [pins, setPins] = useState<Pin[]>([]);
2621
const [loading, setLoading] = useState(true);
2722
const [currentLocation, setCurrentLocation] = useState({
@@ -98,11 +93,6 @@ const MapScreen: React.FC<MapScreenProps> = () => {
9893
return false;
9994
}
10095

101-
if (!pin.location) {
102-
console.warn(`🗺️ [MAP] Pin ${index} missing location:`, pin);
103-
return false;
104-
}
105-
10696
if (typeof pin.location.lat !== 'number' || isNaN(pin.location.lat)) {
10797
console.warn(`🗺️ [MAP] Pin ${index} invalid latitude:`, pin.location.lat);
10898
return false;

client/src/services/api.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ interface AuthResponse {
2828

2929
class ApiService {
3030
private baseURL: string;
31+
private onUnauthorized?: () => Promise<void>;
3132

3233
constructor() {
3334
this.baseURL = Config.API_BASE_URL;
@@ -37,6 +38,10 @@ class ApiService {
3738
this.setupDefaultTimeout();
3839
}
3940

41+
setUnauthorizedHandler(handler: () => Promise<void>) {
42+
this.onUnauthorized = handler;
43+
}
44+
4045
// Setup default timeout for all requests
4146
private setupDefaultTimeout() {
4247
axios.defaults.timeout = 15000; // 15 second timeout
@@ -68,10 +73,10 @@ class ApiService {
6873
if (token && isApiRequest) {
6974
config.headers.Authorization = `Bearer ${token}`;
7075
console.log(`✅ Adding auth token to request: ${config.url}`);
71-
console.log(`🔑 Token preview: ${token.substring(0, 20)}...`);
7276
} else if (isApiRequest) {
7377
console.log(`❌ No token found for API request: ${config.url}`);
7478
}
79+
7580
return config;
7681
},
7782
(error) => {
@@ -83,10 +88,12 @@ class ApiService {
8388
axios.interceptors.response.use(
8489
(response) => response,
8590
async (error) => {
86-
if (error.response?.status === 401) {
91+
if (error.response?.status === 401 || error.response?.status === 500 || error.response?.status === 403) {
8792
// Token expired or invalid
8893
await this.clearToken();
89-
// Could trigger logout here if needed
94+
if (this.onUnauthorized) {
95+
await this.onUnauthorized();
96+
}
9097
}
9198
return Promise.reject(error);
9299
}
@@ -139,10 +146,6 @@ class ApiService {
139146
async register(userData: RegisterRequest): Promise<AuthResponse> {
140147
const response = await axios.post(`${this.baseURL}/auth/register`, userData);
141148
const authData = response.data;
142-
console.log('Register response:', {
143-
token_preview: authData.token?.access_token?.substring(0, 20) + '...',
144-
user: authData.user
145-
});
146149
await this.setToken(authData.token.access_token);
147150
console.log('Token stored successfully');
148151
return authData;

0 commit comments

Comments
 (0)