# profile (https://docs.salla.dev/twilight/react/api/modules/profile)



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](https://docs.salla.dev/twilight/react/api/modules/user).

```tsx title="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:

```tsx title="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 [#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 [#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](https://docs.salla.dev/twilight/react/api/errors-timeouts-and-retries).
* 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](https://docs.salla.dev/twilight/react/api/modules/user), invalidate that key.

## See also [#see-also]

* [Account profile route](https://docs.salla.dev/twilight/react/routes/account-profile)
* [Authentication and scope](https://docs.salla.dev/twilight/react/api/authentication-and-scope)
