mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 12:11:12 -05:00
Fix profile privacy and simplify code
This commit is contained in:
@@ -1,49 +1,15 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { MapPin } from 'lucide-react';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
|
||||
interface LocationDisplayProps {
|
||||
location: {
|
||||
city?: string;
|
||||
country: string;
|
||||
};
|
||||
userId: string;
|
||||
isOwnProfile: boolean;
|
||||
} | null | undefined;
|
||||
}
|
||||
|
||||
export function LocationDisplay({ location, userId, isOwnProfile }: LocationDisplayProps) {
|
||||
const [showLocation, setShowLocation] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
fetchLocationPrivacy();
|
||||
}, [userId, isOwnProfile]);
|
||||
|
||||
const fetchLocationPrivacy = async () => {
|
||||
try {
|
||||
const { data: { user } } = await supabase.auth.getUser();
|
||||
const viewerId = user?.id;
|
||||
|
||||
// Use the secure function to check location visibility
|
||||
const { data, error } = await supabase
|
||||
.rpc('can_view_user_location', {
|
||||
_viewer_id: viewerId,
|
||||
_profile_user_id: userId
|
||||
});
|
||||
|
||||
if (error) {
|
||||
console.error('Error checking location privacy:', error);
|
||||
setShowLocation(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setShowLocation(data || false);
|
||||
} catch (error) {
|
||||
console.error('Error checking location privacy:', error);
|
||||
setShowLocation(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (!showLocation) {
|
||||
export function LocationDisplay({ location }: LocationDisplayProps) {
|
||||
// get_filtered_profile() already handles privacy - if location is present, it's viewable
|
||||
if (!location) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -53,4 +19,4 @@ export function LocationDisplay({ location, userId, isOwnProfile }: LocationDisp
|
||||
{location.city ? `${location.city}, ${location.country}` : location.country}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,46 +1,12 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { MapPin } from 'lucide-react';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
|
||||
interface PersonalLocationDisplayProps {
|
||||
personalLocation: string;
|
||||
userId: string;
|
||||
isOwnProfile: boolean;
|
||||
personalLocation: string | null | undefined;
|
||||
}
|
||||
|
||||
export function PersonalLocationDisplay({ personalLocation, userId, isOwnProfile }: PersonalLocationDisplayProps) {
|
||||
const [showLocation, setShowLocation] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
fetchLocationPrivacy();
|
||||
}, [userId, isOwnProfile]);
|
||||
|
||||
const fetchLocationPrivacy = async () => {
|
||||
try {
|
||||
const { data: { user } } = await supabase.auth.getUser();
|
||||
const viewerId = user?.id;
|
||||
|
||||
// Use the secure function to check location visibility
|
||||
const { data, error } = await supabase
|
||||
.rpc('can_view_user_location', {
|
||||
_viewer_id: viewerId,
|
||||
_profile_user_id: userId
|
||||
});
|
||||
|
||||
if (error) {
|
||||
console.error('Error checking location privacy:', error);
|
||||
setShowLocation(false);
|
||||
return;
|
||||
}
|
||||
|
||||
setShowLocation(data || false);
|
||||
} catch (error) {
|
||||
console.error('Error fetching location privacy:', error);
|
||||
setShowLocation(false);
|
||||
}
|
||||
};
|
||||
|
||||
if (!showLocation || !personalLocation) {
|
||||
export function PersonalLocationDisplay({ personalLocation }: PersonalLocationDisplayProps) {
|
||||
// get_filtered_profile() already handles privacy - if personalLocation is present, it's viewable
|
||||
if (!personalLocation) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user