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.

app/components/MarketingToggle.tsx
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:

app/components/DeleteAccount.tsx
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

MethodParametersReturnsRequestLogin needed
profile.deletenonePromise<void>DELETE profileYes
profile.updateSettingsname: string, value: booleanPromise<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.
  • DELETE is retried by the client on 5xx and 429; POST is 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.

See also

On this page