mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 17:11:12 -05:00
Reverted to commit 96a961d95c
This commit is contained in:
@@ -78,7 +78,6 @@ export function useAdminSettings() {
|
||||
return settings?.filter(s => s.category === category) || [];
|
||||
};
|
||||
|
||||
|
||||
const updateSetting = async (key: string, value: any) => {
|
||||
return updateSettingMutation.mutateAsync({ key, value });
|
||||
};
|
||||
|
||||
@@ -93,24 +93,13 @@ function AuthProviderComponent({ children }: { children: React.ReactNode }) {
|
||||
const {
|
||||
data: { subscription },
|
||||
} = supabase.auth.onAuthStateChange((event, session) => {
|
||||
console.log('[Auth] State change:', event, 'User:', session?.user?.email || 'none');
|
||||
|
||||
if (!isMountedRef.current) return;
|
||||
|
||||
const currentEmail = session?.user?.email;
|
||||
const newEmailPending = session?.user?.new_email;
|
||||
|
||||
// Explicitly handle SIGNED_IN event for iframe compatibility
|
||||
if (event === 'SIGNED_IN' && session) {
|
||||
console.log('[Auth] SIGNED_IN detected, setting session and user');
|
||||
setSession(session);
|
||||
setUser(session.user);
|
||||
setLoading(false);
|
||||
} else {
|
||||
setSession(session);
|
||||
setUser(session?.user ?? null);
|
||||
setLoading(false);
|
||||
}
|
||||
setSession(session);
|
||||
setUser(session?.user ?? null);
|
||||
|
||||
// Track pending email changes
|
||||
setPendingEmail(newEmailPending ?? null);
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export function useCaptchaBypass() {
|
||||
// Single layer: Check if environment allows bypass
|
||||
const bypassEnabled = import.meta.env.VITE_ALLOW_CAPTCHA_BYPASS === 'true';
|
||||
|
||||
// Log warning if bypass is active
|
||||
useEffect(() => {
|
||||
if (bypassEnabled && typeof window !== 'undefined') {
|
||||
console.warn(
|
||||
'⚠️ CAPTCHA BYPASS IS ACTIVE\n' +
|
||||
'CAPTCHA verification is disabled via VITE_ALLOW_CAPTCHA_BYPASS=true\n' +
|
||||
'This should ONLY be enabled in development/preview environments.\n' +
|
||||
'Ensure VITE_ALLOW_CAPTCHA_BYPASS=false in production!'
|
||||
);
|
||||
}
|
||||
}, [bypassEnabled]);
|
||||
|
||||
return {
|
||||
bypassEnabled,
|
||||
requireCaptcha: !bypassEnabled,
|
||||
};
|
||||
}
|
||||
@@ -294,7 +294,7 @@ export function useEntityVersions(entityType: string, entityId: string) {
|
||||
channelRef.current = null;
|
||||
}
|
||||
};
|
||||
}, [entityType, entityId]);
|
||||
}, [entityType, entityId, fetchVersions]);
|
||||
|
||||
// Set mounted ref on mount and cleanup on unmount
|
||||
useEffect(() => {
|
||||
|
||||
@@ -24,36 +24,27 @@ export function useLocationAutoDetect() {
|
||||
// Only run auto-detection after preferences have loaded
|
||||
if (loading) return;
|
||||
|
||||
// Defer auto-detection to not block initial render
|
||||
const timeoutId = setTimeout(() => {
|
||||
try {
|
||||
// Check if localStorage is available
|
||||
if (!isLocalStorageAvailable()) {
|
||||
console.warn('localStorage is not available, skipping location auto-detection');
|
||||
return;
|
||||
// Check if localStorage is available
|
||||
if (!isLocalStorageAvailable()) {
|
||||
console.warn('localStorage is not available, skipping location auto-detection');
|
||||
return;
|
||||
}
|
||||
|
||||
// Check if we've already attempted detection
|
||||
const hasAttemptedDetection = localStorage.getItem('location_detection_attempted');
|
||||
|
||||
// Auto-detect if we haven't attempted it yet and auto_detect is enabled
|
||||
if (preferences.auto_detect && !hasAttemptedDetection) {
|
||||
autoDetectPreferences().then(() => {
|
||||
if (isLocalStorageAvailable()) {
|
||||
localStorage.setItem('location_detection_attempted', 'true');
|
||||
}
|
||||
|
||||
// Check if we've already attempted detection
|
||||
const hasAttemptedDetection = localStorage.getItem('location_detection_attempted');
|
||||
|
||||
// Auto-detect if we haven't attempted it yet and auto_detect is enabled
|
||||
if (preferences.auto_detect && !hasAttemptedDetection) {
|
||||
autoDetectPreferences().then(() => {
|
||||
if (isLocalStorageAvailable()) {
|
||||
localStorage.setItem('location_detection_attempted', 'true');
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.error('❌ Failed to auto-detect location:', error);
|
||||
if (isLocalStorageAvailable()) {
|
||||
localStorage.setItem('location_detection_attempted', 'true');
|
||||
}
|
||||
});
|
||||
}).catch((error) => {
|
||||
console.error('❌ Failed to auto-detect location:', error);
|
||||
if (isLocalStorageAvailable()) {
|
||||
localStorage.setItem('location_detection_attempted', 'true');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('❌ Error in location auto-detection:', error);
|
||||
}
|
||||
}, 1000); // Defer by 1 second to allow app to render first
|
||||
|
||||
return () => clearTimeout(timeoutId);
|
||||
}, [user, loading, preferences.auto_detect, autoDetectPreferences]);
|
||||
});
|
||||
}
|
||||
}, [user, loading, preferences.auto_detect]);
|
||||
}
|
||||
@@ -15,25 +15,7 @@ export function useUnitPreferences() {
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
let mounted = true;
|
||||
|
||||
const load = async () => {
|
||||
try {
|
||||
await loadPreferences();
|
||||
} catch (error) {
|
||||
console.error('Failed to load preferences:', error);
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setLoading(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
load();
|
||||
|
||||
return () => {
|
||||
mounted = false;
|
||||
};
|
||||
loadPreferences();
|
||||
}, [user]);
|
||||
|
||||
const loadPreferences = async () => {
|
||||
@@ -76,15 +58,7 @@ export function useUnitPreferences() {
|
||||
|
||||
const autoDetectPreferences = useCallback(async () => {
|
||||
try {
|
||||
// Add timeout to prevent hanging
|
||||
const timeoutPromise = new Promise((_, reject) =>
|
||||
setTimeout(() => reject(new Error('Location detection timeout')), 5000)
|
||||
);
|
||||
|
||||
const response = await Promise.race([
|
||||
supabase.functions.invoke('detect-location'),
|
||||
timeoutPromise
|
||||
]) as any;
|
||||
const response = await supabase.functions.invoke('detect-location');
|
||||
|
||||
if (response.data && response.data.measurementSystem) {
|
||||
const newPreferences: UnitPreferences = {
|
||||
|
||||
Reference in New Issue
Block a user