mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 05:11:13 -05:00
Refactor security policies
This commit is contained in:
@@ -19,25 +19,26 @@ export function LocationDisplay({ location, userId, isOwnProfile }: LocationDisp
|
||||
}, [userId, isOwnProfile]);
|
||||
|
||||
const fetchLocationPrivacy = async () => {
|
||||
// Always show location for own profile
|
||||
if (isOwnProfile) {
|
||||
setShowLocation(true);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const { data } = await supabase
|
||||
.from('user_preferences')
|
||||
.select('privacy_settings')
|
||||
.eq('user_id', userId)
|
||||
.maybeSingle();
|
||||
const { data: { user } } = await supabase.auth.getUser();
|
||||
const viewerId = user?.id;
|
||||
|
||||
if (data?.privacy_settings) {
|
||||
const settings = data.privacy_settings as any;
|
||||
setShowLocation(settings.show_location || false);
|
||||
// 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);
|
||||
console.error('Error checking location privacy:', error);
|
||||
setShowLocation(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -16,23 +16,24 @@ export function PersonalLocationDisplay({ personalLocation, userId, isOwnProfile
|
||||
}, [userId, isOwnProfile]);
|
||||
|
||||
const fetchLocationPrivacy = async () => {
|
||||
// Always show location for own profile
|
||||
if (isOwnProfile) {
|
||||
setShowLocation(true);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const { data } = await supabase
|
||||
.from('user_preferences')
|
||||
.select('privacy_settings')
|
||||
.eq('user_id', userId)
|
||||
.maybeSingle();
|
||||
const { data: { user } } = await supabase.auth.getUser();
|
||||
const viewerId = user?.id;
|
||||
|
||||
if (data?.privacy_settings) {
|
||||
const settings = data.privacy_settings as any;
|
||||
setShowLocation(settings.show_location || false);
|
||||
// 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);
|
||||
|
||||
Reference in New Issue
Block a user