Create profile for all authenticated users, not just OAuth users

cgen-73f85d66299a42b3b9994ce907b7b0b7
This commit is contained in:
Builder.io 2025-08-16 04:24:06 +00:00
parent cc5469a7dc
commit b2d984770e

View file

@ -79,8 +79,8 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
if (session?.user) { if (session?.user) {
const profile = await fetchUserProfile(session.user.id); const profile = await fetchUserProfile(session.user.id);
// Create profile for new OAuth users // Create profile for any user that doesn't have one
if (!profile && session.user.app_metadata?.provider) { if (!profile) {
try { try {
await aethexUserService.createInitialProfile(session.user.id, { await aethexUserService.createInitialProfile(session.user.id, {
username: username:
@ -94,19 +94,19 @@ export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({
session.user.email?.split("@")[0], session.user.email?.split("@")[0],
email: session.user.email, email: session.user.email,
avatar_url: session.user.user_metadata?.avatar_url, avatar_url: session.user.user_metadata?.avatar_url,
user_type: "community_member", // Default for OAuth users user_type: "community_member", // Default type
experience_level: "beginner", experience_level: "beginner",
}); });
// Fetch the newly created profile // Fetch the newly created profile
await fetchUserProfile(session.user.id); await fetchUserProfile(session.user.id);
// Award onboarding achievement for OAuth users // Award onboarding achievement
await aethexAchievementService.checkAndAwardOnboardingAchievement( await aethexAchievementService.checkAndAwardOnboardingAchievement(
session.user.id, session.user.id,
); );
} catch (error) { } catch (error) {
console.error("Error creating OAuth user profile:", error); console.error("Error creating user profile:", error);
} }
} }
} else { } else {