profile
Deletes the customer's account and saves a single account preference.
Use profile for the two write calls an account page needs. It is the smallest module and has no queries, because nothing is read through it. To read the customer, use user.
import { profile } from '@salla.sa/twilight-theme-engine/api/profile';
export function MarketingToggle() {
async function onChange(checked: boolean) {
await profile.updateSettings('is_notifiable', checked);
}
return <input type="checkbox" onChange={(event) => onChange(event.target.checked)} />;
}Writes do not belong in a loader. Call them from an event handler, or from a mutation to get pending and error state:
import { useMutation } from '@tanstack/react-query';
import { profile } from '@salla.sa/twilight-theme-engine/api/profile';
export function DeleteAccount() {
const del = useMutation({ mutationFn: () => profile.delete() });
return (
<button disabled={del.isPending} onClick={() => del.mutate()}>
Delete my account
</button>
);
}Methods
| Method | Parameters | Returns | Request | Login needed |
|---|---|---|---|---|
profile.delete | none | Promise<void> | DELETE profile | Yes |
profile.updateSettings | name: string, value: boolean | Promise<void> | POST profile/settings with JSON { name, value } | Yes |
updateSettings saves one preference at a time, for example is_notifiable for marketing messages. value is a boolean only.
Gotchas
- Neither method checks for a token. A guest request is rejected by the API and throws an
HTTPError; errors are not swallowed. DELETEis retried by the client on 5xx and 429;POSTis not. See Errors.- After deleting, the module does not end the session or clear the cache. Log the customer out and clear query data yourself. If you cache the customer with user, invalidate that key.