profile

Update the customer's details, change their email or mobile with a code, update settings and delete the account.

Use Salla.profile on account pages, when the logged-in customer changes their own details. To read the customer for a page, use useUser.

await Salla.profile.update({
  first_name: 'Sara',
  last_name: 'Ahmed',
  birthday: '1995-02-22',
  gender: 'female',
});

Methods

MethodParametersDoes
infononeLoads the customer's profile and saves it in Salla.config.get('user')
update{ first_name?, last_name?, birthday?, gender?, ... }Updates the profile
updateContacts{ email } or { phone, country_code }Starts changing the email or mobile. The store sends a code.
verify{ type, code, email } or { type, code, phone, country_code }Confirms the new email or mobile with the code
getFieldsnoneThe store's extra profile fields. An empty list on failure.
updateCustomFieldsthe extra fieldsSaves the extra profile fields
updateSettings{ name, value }Saves one setting, such as { name: 'is_notifiable', value: true } for promotional messages
deletenoneRemoves the account at once, with no code, then logs the customer out

Change the email or mobile

A new email or mobile must be confirmed with a code, like a login. updateContacts sends the code; verify checks it.

const response = await Salla.profile.updateContacts({ phone: '555555555', country_code: 'SA' });

if (response.data.verification?.status === 'pending') {
  // ask the customer for the code, then:
  await Salla.profile.verify({
    type: response.data.verification.type,          // 'phone' or 'email'
    code: '1111',
    phone: response.data.phone.number,
    country_code: response.data.phone.country,
  });
}

For an email, pass email: response.data.email instead of the phone fields. The salla-verify web component asks for the code for you. See salla-verify.

Ask before deleting

When the store has the customer-account-deletion feature, deleting the account is a request confirmed with a code. These four methods run it. They show no messages and fire no events:

MethodParametersDoes
initiateDeleteRequesttypeStarts the request and sends a code by type
verifyDeleteRequest{ type, code }Confirms it with the code
getDeleteRequestnoneReads the open request, if any
cancelDeleteRequestnoneCancels it

Events

EventFires whenArguments
profile::info.fetched / profile::info.not.fetchedinforesponse or error
profile::updated / profile::update.failedupdate, updateCustomFieldsresponse or error
profile::verification.code.sent / profile::update.contacts.failedupdateContactsresponse or error
profile::verified / profile::unverifiedverifyresponse or error
profile::settings.updated / profile::update.settings.failedupdateSettingsresponse or error
profile::deleted / profile::not.deleteddeleteresponse or error

Gotchas

  • On a store with Salla single sign-on, update and updateCustomFields reject and show "SSO login is enabled. You cannot update your profile."
  • After update, Salla.config.get('user') holds the new values. React state from useUser does not update on its own: refetch it.
  • delete clears the browser's saved data and leaves the page. Fire your own clean-up from profile::deleted.

See also

On this page