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
| Method | Parameters | Does |
|---|---|---|
info | none | Loads 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 |
getFields | none | The store's extra profile fields. An empty list on failure. |
updateCustomFields | the extra fields | Saves the extra profile fields |
updateSettings | { name, value } | Saves one setting, such as { name: 'is_notifiable', value: true } for promotional messages |
delete | none | Removes 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:
| Method | Parameters | Does |
|---|---|---|
initiateDeleteRequest | type | Starts the request and sends a code by type |
verifyDeleteRequest | { type, code } | Confirms it with the code |
getDeleteRequest | none | Reads the open request, if any |
cancelDeleteRequest | none | Cancels it |
Events
| Event | Fires when | Arguments |
|---|---|---|
profile::info.fetched / profile::info.not.fetched | info | response or error |
profile::updated / profile::update.failed | update, updateCustomFields | response or error |
profile::verification.code.sent / profile::update.contacts.failed | updateContacts | response or error |
profile::verified / profile::unverified | verify | response or error |
profile::settings.updated / profile::update.settings.failed | updateSettings | response or error |
profile::deleted / profile::not.deleted | delete | response or error |
Gotchas
- On a store with Salla single sign-on,
updateandupdateCustomFieldsreject and show "SSO login is enabled. You cannot update your profile." - After
update,Salla.config.get('user')holds the new values. React state fromuseUserdoes not update on its own: refetch it. deleteclears the browser's saved data and leaves the page. Fire your own clean-up fromprofile::deleted.