diff --git a/src/pages/Dashboard.tsx b/src/pages/Dashboard.tsx index 5c98cae1..e07ac409 100644 --- a/src/pages/Dashboard.tsx +++ b/src/pages/Dashboard.tsx @@ -41,6 +41,40 @@ export default function Dashboard() { if (error) throw error; + // Auto-sync user metadata from Auth to profiles if missing + if (data) { + const needsUpdate: any = {}; + + // Sync full_name from Auth metadata if not set in profiles + if (!data.full_name && user.user_metadata?.full_name) { + needsUpdate.full_name = user.user_metadata.full_name; + } + + // Sync phone from Auth metadata if not set in profiles + if (!data.phone_number && user.user_metadata?.phone) { + needsUpdate.phone_number = user.user_metadata.phone; + } + + // Sync email if not set + if (!data.email && user.email) { + needsUpdate.email = user.email; + } + + // If there are fields to update, update the profile + if (Object.keys(needsUpdate).length > 0) { + console.log('🔄 Syncing profile from Auth metadata:', needsUpdate); + const { error: updateError } = await supabase + .from('profiles') + .update(needsUpdate) + .eq('id', user.id); + + if (!updateError) { + // Update local state + Object.assign(data, needsUpdate); + } + } + } + // Note: Email verification is handled by Supabase Auth (user.email_confirmed_at) // We don't store it in profiles table to avoid duplication diff --git a/src/pages/ProfileSettings.tsx b/src/pages/ProfileSettings.tsx index 4ea3996d..33deab67 100644 --- a/src/pages/ProfileSettings.tsx +++ b/src/pages/ProfileSettings.tsx @@ -23,7 +23,9 @@ export default function ProfileSettings() { username: '', full_name: '', bio: '', - phone: '', + phone_number: '', + location: '', + website: '', language: 'en', theme: 'light', notifications_email: true, @@ -51,7 +53,9 @@ export default function ProfileSettings() { username: data.username || '', full_name: data.full_name || '', bio: data.bio || '', - phone: data.phone || '', + phone_number: data.phone_number || '', + location: data.location || '', + website: data.website || '', language: data.language || 'en', theme: data.theme || 'light', notifications_email: data.notifications_email ?? true, @@ -74,7 +78,9 @@ export default function ProfileSettings() { username: profile.username, full_name: profile.full_name, bio: profile.bio, - phone: profile.phone, + phone_number: profile.phone_number, + location: profile.location, + website: profile.website, language: profile.language, theme: profile.theme, updated_at: new Date().toISOString() @@ -247,11 +253,27 @@ export default function ProfileSettings() {
setProfile({ ...profile, phone: e.target.value })} + value={profile.phone_number} + onChange={(e) => setProfile({ ...profile, phone_number: e.target.value })} placeholder="+1234567890" />
+
+ + setProfile({ ...profile, location: e.target.value })} + placeholder="City, Country" + /> +
+
+ + setProfile({ ...profile, website: e.target.value })} + placeholder="https://example.com" + /> +