> For the complete documentation index, see [llms.txt](https://docs.baas.sh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.baas.sh/baas-sdk/manage-user.md).

# Manage user

Manage the signed-in user's profile and find their contract events with filters.

Use `baas.user` to manage the signed-in user's profile or [find their transfers](#filter-the-users-history).

## Methods

```ts
// Read the profile
const user = await baas.user.getUser();
//  → BaasUser

// Email
await baas.user.setEmail('alice@example.com');

// FCM tokens
await baas.user.addFcmToken(token);
await baas.user.removeFcmToken(token);
```

{% hint style="info" %}
A real FCM token comes from the Firebase Web Push client (a service worker plus a permission prompt). See [Push notifications](/baas-sdk/integrations/push-notifications.md) for the full setup.
{% endhint %}

`getUser()` resolves to a `BaasUser`: `address`, `email`, `fcmTokens` and `createdAt` (see the [API reference](/baas-sdk/resources/api-reference.md#types)).

Use `getUser()` for the email or FCM tokens, for example to pre-fill a settings form. For the wallet address or current auth state, use `baas.auth.getSession()`.

The SDK reads and updates the signed-in user only; reading anyone else is a job for your backend, with a [secret key](/baas-console/api-settings/secret-keys.md). Signed out, every method throws `NOT_SIGNED_IN`.

An invalid value comes back as a `BaasApiError` with `.status === 400`; `err.body.errors` names the field and the reason.

Adding a token that is already there, or removing one that is not, does nothing. The email is normalized to lowercase and trimmed (`Alice@Example.com` becomes `alice@example.com`); the change is immediate, no verification email is sent, and the user signs in with the new address from then on. The passkey and the wallet address stay the same.

Email ownership is not verified. Do not use this field alone to authorize account recovery or privileged actions.

## Read the user's history

Read events that involve the signed-in user on one contract. Sign in and select the deployment's network first; history starts when the contract is registered.

Replace `tokenAddress` with the contract's deployment address:

```ts
const page = await baas.user.events({ address: tokenAddress });

console.log(page.data);  // this user's events, newest first
console.log(page.nextCursor); // cursor for the next page, or null
```

BaaS uses the signed-in user's wallet automatically. The contract's [event mappings](/baas-console/contracts/mappings.md) identify their role, returned in each event's `directions`:

| Value     | Meaning                                                     |
| --------- | ----------------------------------------------------------- |
| `out`     | Sender                                                      |
| `in`      | Recipient                                                   |
| `related` | Another participant, only when neither sender nor recipient |

A transfer to yourself can have both `out` and `in`.

### Filter the user's history

Find transfers of **at least 10 tokens received from Alice**. Both versions below select the same events:

{% tabs %}
{% tab title="Helpers" %}

```ts
import { and, eq, gte, SmartUnits } from '@baas.sh/sdk';

const alice = '0x1111111111111111111111111111111111111111';
const where = and(
  eq('direction', 'in'),
  eq('args.from', alice),
  gte('args.value', SmartUnits('10')),
);

const received = await baas.user.events({
  address: tokenAddress,
  event: 'Transfer',
  where,
  limit: 20,
});

console.log(received.data);
console.log(received.nextCursor); // null when there is no next page
```

{% endtab %}

{% tab title="JSON" %}
Use this object as `where` in the same `baas.user.events()` call:

```json
{
  "combinator": "and",
  "rules": [
    { "field": "direction", "operator": "=", "value": "in" },
    { "field": "args.from", "operator": "=", "value": "0x1111111111111111111111111111111111111111" },
    {
      "field": "args.value",
      "operator": ">=",
      "value": { "value": "10", "encoding": "units", "baasSdkInput": true }
    }
  ]
}
```

{% endtab %}
{% endtabs %}

[Smart Units](/baas-sdk/blockchain/smart-units.md) let you enter tokens directly when the event argument has a unit. Use `eq('direction', 'out')` for sent transfers. To combine alternatives, nest an [`or(...)` group](/baas-sdk/blockchain/events.md#combine-conditions) inside `and(...)`.

User-history filters use `direction` instead of `wallet`; `direction` accepts only `eq`. Every result still belongs to the signed-in user, including with `or` groups. To read all users' events on the contract, use [contract history](/baas-sdk/blockchain/events.md).

See [all fields and operators](/baas-sdk/blockchain/events.md#write-rules) to filter by date, key or other event arguments.

Keep the same contract, event and filters, and pass `nextCursor` as `cursor` for more results; stop when it is null. The default `limit` is 20, up to 100; see [pagination](/baas-sdk/blockchain/events.md#page-through-events).

### Count the user's events

`baas.user.eventsCount` takes the same `address`, `event` and `where`, without `cursor` or `limit`, and returns the total:

```ts
const { count } = await baas.user.eventsCount({ address: tokenAddress, event: 'Transfer', where });
console.log(count); // "12", a decimal string
```

## Handling errors

```ts
import { BaasApiError, BaasAuthError } from '@baas.sh/sdk';

try {
  await baas.user.setEmail(userInput);
} catch (err) {
  if (err instanceof BaasAuthError && err.code === 'NOT_SIGNED_IN') {
    // prompt sign-in
  } else if (err instanceof BaasApiError && err.status === 400) {
    const { errors } = err.body as { errors?: { field: string; message: string }[] };
    showToast(errors?.[0]?.message ?? err.message);
  } else if (err instanceof BaasApiError && err.status === 409) {
    // another account already uses this email (err.body.code === 'email_already_in_use')
  }
}
```

## Next

* [Error handling](/baas-sdk/resources/error-handling.md) — handle `NOT_SIGNED_IN` and validation errors cleanly.
* [Sessions](/baas-sdk/authentication/sessions.md) — confirm the active session before calling these methods.
* [Push notifications](/baas-sdk/integrations/push-notifications.md) — set up the Firebase Web Push client and deliver notifications.
