Update profile save to work with mock auth

cgen-eb29c0c13568447782a2007c6bfa8b97
This commit is contained in:
Builder.io 2025-08-17 00:16:28 +00:00
parent 491f6eaf06
commit a8a0cf7d1a

View file

@ -197,22 +197,41 @@ export default function Profile() {
// Check if profile exists, create if it doesn't // Check if profile exists, create if it doesn't
if (!profile) { if (!profile) {
console.log("No profile exists, creating one..."); console.log("No profile exists, creating one...");
// Create initial profile if it doesn't exist
const { data, error } = await supabase try {
.from("user_profiles") // Try using the AuthContext updateProfile (which works with mock too)
.insert({ await updateProfile({
id: user.id,
username: profileData.displayName || user.email?.split('@')[0] || `user_${Date.now()}`, username: profileData.displayName || user.email?.split('@')[0] || `user_${Date.now()}`,
email: user.email,
role: "member",
onboarded: true,
full_name: profileData.displayName, full_name: profileData.displayName,
bio: profileData.bio, bio: profileData.bio,
location: profileData.location, location: profileData.location,
linkedin_url: profileData.linkedinUrl, linkedin_url: profileData.linkedinUrl,
github_url: profileData.githubUsername ? `https://github.com/${profileData.githubUsername}` : null, github_url: profileData.githubUsername ? `https://github.com/${profileData.githubUsername}` : null,
twitter_url: profileData.twitterUsername ? `https://twitter.com/${profileData.twitterUsername}` : null, twitter_url: profileData.twitterUsername ? `https://twitter.com/${profileData.twitterUsername}` : null,
loyalty_points: 0, user_type: "community_member",
experience_level: "beginner",
level: 1,
total_xp: 0,
} as any);
console.log("Profile created successfully via AuthContext");
} catch (authError) {
console.warn("AuthContext creation failed, trying direct database:", authError);
// Fallback to direct database call
const { data, error } = await supabase
.from("user_profiles")
.insert({
id: user.id,
username: profileData.displayName || user.email?.split('@')[0] || `user_${Date.now()}`,
user_type: "community_member",
experience_level: "beginner",
full_name: profileData.displayName,
bio: profileData.bio,
location: profileData.location,
linkedin_url: profileData.linkedinUrl,
github_url: profileData.githubUsername ? `https://github.com/${profileData.githubUsername}` : null,
twitter_url: profileData.twitterUsername ? `https://twitter.com/${profileData.twitterUsername}` : null,
level: 1, level: 1,
total_xp: 0, total_xp: 0,
created_at: new Date().toISOString(), created_at: new Date().toISOString(),
@ -226,7 +245,8 @@ export default function Profile() {
throw error; throw error;
} }
console.log("Profile created successfully:", data); console.log("Profile created successfully via direct DB:", data);
}
} else { } else {
console.log("Updating existing profile..."); console.log("Updating existing profile...");
await updateProfile({ await updateProfile({