# User Attributes

User attributes are typed profile fields your organization defines in the Allegro admin — things like a newsletter opt-in, a favorite topic, or any preference you want a member to control. This guide covers reading and writing them from the browser with the SDK, which is how you'd build a preference center on your site.

Attributes are defined by an operator first. See the [User Attributes product guide](/product/audience/user-attributes.md) for how to create them and what the types mean.

Requires a signed-in member

These methods act on the currently authenticated member. Call them after the member has signed in — an unauthenticated visitor has no profile to read or write.

## Reading a member's attributes[​](#reading-a-members-attributes "Direct link to Reading a member's attributes")

`allegro.member.getUserAttributes()` returns every defined attribute merged with the current member's value, so you can render a whole preference form from one call:

```js
window.allegro.push(async function (allegro) {
    const attributes = await allegro.member.getUserAttributes();

    attributes.forEach(function (attribute) {
        console.log(attribute.slug, attribute.value);
    });
});

```

Each entry has the attribute's definition plus the member's current value:

| Field         | Type               | Description                                             |
| ------------- | ------------------ | ------------------------------------------------------- |
| `slug`        | `string`           | The attribute key.                                      |
| `name`        | `string`           | The human-readable label.                               |
| `description` | `string \| null`   | The optional description.                               |
| `type`        | `string`           | `string`, `number`, `boolean`, or `enum`.               |
| `options`     | `string[] \| null` | The allowed choices, when the type is `enum`.           |
| `value`       | `unknown`          | The member's current value, or `null` when none is set. |

Every defined attribute appears in the list, whether or not the member has set a value for it.

## Setting a value[​](#setting-a-value "Direct link to Setting a value")

`allegro.member.setUserAttribute(slug, value)` sets the value for the current member and resolves with the stored value:

```js
window.allegro.push(async function (allegro) {
    await allegro.member.setUserAttribute('wants-newsletter', true);
});

```

The value must match the attribute's type — a boolean for a boolean attribute, one of the defined options for an `enum` attribute, and so on. A value that fails validation, or a `slug` that isn't a defined attribute, is rejected.

## Clearing a value[​](#clearing-a-value "Direct link to Clearing a value")

`allegro.member.deleteUserAttribute(slug)` removes the member's value for an attribute:

```js
window.allegro.push(async function (allegro) {
    await allegro.member.deleteUserAttribute('wants-newsletter');
});

```

## Keeping the session token current[​](#keeping-the-session-token-current "Direct link to Keeping the session token current")

Setting or clearing a value changes the member's [session token](/developer/guides/jwt.md) — attribute values are carried in its `user_attributes` claim. The SDK stores the freshly-issued token automatically after each write, so a subsequent `allegro.member.getJwt()` returns a token that reflects the change.

## Related[​](#related "Direct link to Related")

* [User Attributes product guide](/product/audience/user-attributes.md) — Define attributes and their types in the admin.
* [JWT Verification](/developer/guides/jwt.md) — Read attribute values from the session token.
* [`MemberNamespace`](/developer/api-reference/interfaces/MemberNamespace.md) — Full SDK member API reference.
