From ca510ead8640b025e7741096dcf0439afd6ab537 Mon Sep 17 00:00:00 2001 From: Kurdistan Tech Ministry Date: Wed, 29 Oct 2025 04:30:43 +0300 Subject: [PATCH] debug: Add comprehensive logging to profile save/fetch operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added detailed console logging to track data flow: - ProfileSettings: Log data being saved and save responses - ProfileSettings: Log data being loaded when page opens - Dashboard: Log profile data being fetched and set to state This will help identify where profile data is being lost between save in ProfileSettings and display in Dashboard. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/pages/Dashboard.tsx | 8 +++++- src/pages/ProfileSettings.tsx | 52 +++++++++++++++++++++++------------ 2 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/pages/Dashboard.tsx b/src/pages/Dashboard.tsx index e07ac409..1a8079ec 100644 --- a/src/pages/Dashboard.tsx +++ b/src/pages/Dashboard.tsx @@ -32,6 +32,8 @@ export default function Dashboard() { const fetchProfile = async () => { if (!user) return; + console.log('📥 FETCHING PROFILE for user:', user.id); + try { const { data, error } = await supabase .from('profiles') @@ -39,6 +41,9 @@ export default function Dashboard() { .eq('id', user.id) .single(); + console.log('📊 FETCHED PROFILE DATA:', data); + console.log('❌ Fetch error:', error); + if (error) throw error; // Auto-sync user metadata from Auth to profiles if missing @@ -78,9 +83,10 @@ export default function Dashboard() { // Note: Email verification is handled by Supabase Auth (user.email_confirmed_at) // We don't store it in profiles table to avoid duplication + console.log('✅ SETTING PROFILE STATE TO:', data); setProfile(data); } catch (error) { - console.error('Error fetching profile:', error); + console.error('❌ Error fetching profile:', error); } finally { setLoading(false); } diff --git a/src/pages/ProfileSettings.tsx b/src/pages/ProfileSettings.tsx index 33deab67..ed39ca04 100644 --- a/src/pages/ProfileSettings.tsx +++ b/src/pages/ProfileSettings.tsx @@ -42,14 +42,19 @@ export default function ProfileSettings() { const loadProfile = async () => { try { - const { data } = await supabase + console.log('📥 LOADING PROFILE in ProfileSettings for user:', user?.id); + + const { data, error } = await supabase .from('profiles') .select('*') .eq('id', user?.id) .single(); + console.log('📊 LOADED PROFILE DATA:', data); + console.log('❌ Load error:', error); + if (data) { - setProfile({ + const profileState = { username: data.username || '', full_name: data.full_name || '', bio: data.bio || '', @@ -62,30 +67,42 @@ export default function ProfileSettings() { notifications_push: data.notifications_push ?? false, notifications_sms: data.notifications_sms ?? false, two_factor_enabled: data.two_factor_enabled ?? false - }); + }; + + console.log('✅ SETTING PROFILE STATE TO:', profileState); + setProfile(profileState); } } catch (error) { - console.error('Error loading profile:', error); + console.error('❌ Error loading profile:', error); } }; const updateProfile = async () => { setLoading(true); try { - const { error } = await supabase + const updateData = { + username: profile.username, + full_name: profile.full_name, + bio: profile.bio, + phone_number: profile.phone_number, + location: profile.location, + website: profile.website, + language: profile.language, + theme: profile.theme, + updated_at: new Date().toISOString() + }; + + console.log('💾 SAVING PROFILE DATA:', updateData); + console.log('👤 User ID:', user?.id); + + const { data, error } = await supabase .from('profiles') - .update({ - username: profile.username, - full_name: profile.full_name, - bio: profile.bio, - phone_number: profile.phone_number, - location: profile.location, - website: profile.website, - language: profile.language, - theme: profile.theme, - updated_at: new Date().toISOString() - }) - .eq('id', user?.id); + .update(updateData) + .eq('id', user?.id) + .select(); + + console.log('✅ Save response data:', data); + console.log('❌ Save error:', error); if (error) throw error; @@ -94,6 +111,7 @@ export default function ProfileSettings() { description: 'Profile updated successfully', }); } catch (error) { + console.error('❌ Profile update failed:', error); toast({ title: 'Error', description: 'Failed to update profile',