Avoid duplicate profile insert by updating when profile exists

cgen-457c85dadc6f44d597ff623fcd8a1d1a
This commit is contained in:
Builder.io 2025-09-27 20:22:06 +00:00
parent 4d10efa5df
commit 037b5f2e42

View file

@ -117,13 +117,20 @@ export default function Onboarding() {
customer: "customer",
};
await aethexUserService.createInitialProfile(user.id, {
const existing = await aethexUserService.getCurrentUser();
const payload = {
username: `${data.personalInfo.firstName || user.email?.split("@")[0] || "user"}`,
full_name: `${data.personalInfo.firstName} ${data.personalInfo.lastName}`.trim(),
user_type: (userTypeMap[data.userType || "member"] as any) || "community_member",
experience_level: (data.experience.level as any) || "beginner",
bio: data.experience.previousProjects || undefined,
});
} as any;
if (existing) {
await aethexUserService.updateProfile(user.id, payload);
} else {
await aethexUserService.createInitialProfile(user.id, payload);
}
const interests = Array.from(
new Set([...(data.interests.primaryGoals || []), ...(data.interests.preferredServices || [])]),