debug: Add comprehensive logging to profile save/fetch operations

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 <noreply@anthropic.com>
This commit is contained in:
2025-10-29 04:30:43 +03:00
parent 9ca14ec300
commit ca510ead86
2 changed files with 42 additions and 18 deletions
+7 -1
View File
@@ -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);
}
+35 -17
View File
@@ -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',