mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 02:31:12 -05:00
Fix: Implement field-level privacy for profiles
This commit is contained in:
@@ -234,16 +234,34 @@ export default function Profile() {
|
||||
};
|
||||
const fetchProfile = async (profileUsername: string) => {
|
||||
try {
|
||||
// Use filtered_profiles view for privacy-respecting queries
|
||||
// This view enforces field-level privacy based on user settings
|
||||
const { data, error } = await supabase
|
||||
.from('profiles')
|
||||
.select(`*, location:locations(*)`)
|
||||
.from('filtered_profiles')
|
||||
.select(`*`)
|
||||
.eq('username', profileUsername)
|
||||
.maybeSingle();
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
if (data) {
|
||||
setProfile(data as ProfileType);
|
||||
// Fetch location separately if location_id is visible
|
||||
let locationData = null;
|
||||
if (data.location_id) {
|
||||
const { data: location } = await supabase
|
||||
.from('locations')
|
||||
.select('*')
|
||||
.eq('id', data.location_id)
|
||||
.single();
|
||||
locationData = location;
|
||||
}
|
||||
|
||||
const profileWithLocation = {
|
||||
...data,
|
||||
location: locationData
|
||||
};
|
||||
|
||||
setProfile(profileWithLocation as ProfileType);
|
||||
setEditForm({
|
||||
username: data.username || '',
|
||||
display_name: data.display_name || '',
|
||||
|
||||
Reference in New Issue
Block a user