export async function onHandleUpdateProfileData()

in src/app/(proper_react)/(redesign)/(authenticated)/user/(dashboard)/settings/actions.ts [270:337]


export async function onHandleUpdateProfileData(profileData: OnerepProfileRow) {
  const session = await getServerSession();
  if (!session?.user.subscriber?.id) {
    logger.error(`User does not have an active session.`);
    return {
      success: false,
      error: "update-profile-data-without-active-session",
      errorMessage: `User does not have an active session.`,
    };
  }

  if (!hasPremium(session.user)) {
    logger.error(`User does not have an active subscription.`);
    return {
      success: false,
      error: "update-profile-data-without-active-subscription",
      errorMessage: `User does not have an active subscription.`,
    };
  }

  if (!profileData.onerep_profile_id) {
    logger.error(`User does not have a OneRep profile.`);
    return {
      success: false,
      error: "update-profile-data-without-onerep-profile",
      errorMessage: `User does not have a OneRep profile.`,
    };
  }

  try {
    const {
      first_name,
      middle_name,
      last_name,
      first_names,
      last_names,
      middle_names,
      phone_numbers,
      addresses,
    } = profileData;
    await updateDataBrokerScanProfile(profileData.onerep_profile_id, {
      first_name,
      last_name,
      first_names,
      last_names,
      middle_names,
      phone_numbers,
      addresses,
      middle_name: middle_name ?? "",
    });
  } catch (error) {
    logger.error("Could not update profile details:", error);
    return {
      success: false,
      error: "update-profile-data-updating-profile-failed",
      errorMessage: `Updating profile failed.`,
    };
  }

  // Tell the /edit-info page to display an “details saved” notification:
  (await cookies()).set("justSavedDetails", "justSavedDetails", {
    expires: new Date(Date.now() + 5 * 60 * 1000),
    httpOnly: false,
  });

  revalidatePath("/user/settings/edit-info");
  redirect("/user/settings/edit-info");
}