Skip to content

Custom user profile fields not saved unless standard profile fields are set #768

@lane711

Description

@lane711

Bug Description

When editing a user in the admin UI, custom profile fields defined via defineUserProfile() are not persisted unless at least one standard profile field (display name, bio, company, job title, website, location, or date of birth) also has a value.

Steps to Reproduce

  1. Define a custom user profile field:
defineUserProfile({
  fields: [
    { name: 'plan', label: 'Plan', type: 'radio', options: ['free', 'monthly', 'annual', 'lifetime'], default: 'free', required: true }
  ]
})
  1. Go to Admin → Users → Edit a user
  2. Change the "Plan" radio button to a new value (e.g. "monthly")
  3. Leave all standard profile fields (display name, bio, company, etc.) empty
  4. Click Save
  5. Reload the page — the plan field reverts to the old value

Root Cause

In the admin user PUT handler (userRoutes.put("/users/:id", ...)), the profile save logic is gated on standard fields:

const hasProfileData = profileDisplayName || profileBio || profileCompany || profileJobTitle || profileWebsite || profileLocation || profileDateOfBirth;
if (hasProfileData) {
  // ... UPDATE or INSERT user_profiles including customDataJson ...
}

If all standard profile fields are empty/null, the entire block is skipped — customDataJson is computed but never written to the database.

Fix

The condition should also check for custom data:

if (hasProfileData || customDataJson !== null) {

This ensures custom profile fields are saved even when no standard profile fields are filled in.

Environment

  • @sonicjs-cms/core: 2.12.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions