> 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

The `baas.user` namespace reads and updates the signed-in user's profile. It's kept separate from `baas.auth` because these calls don't affect the session.

## Methods

```ts
// Read the signed-in user's profile.
const user = await baas.user.getUser();
//  → BaasUser

// Email — used by your backend for transactional notifications (onchain alerts,
// recovery links, etc.).
await baas.user.setEmail('alice@example.com'); // set
await baas.user.setEmail(null);                // clear (pass null, not '')

// FCM tokens — Firebase Cloud Messaging device tokens for push notifications.
const token = await getMessaging().getToken();
await baas.user.addFcmToken(token);
await baas.user.removeFcmToken(token);
```

| Method                                   | Description                                               |
| ---------------------------------------- | --------------------------------------------------------- |
| `getUser(): Promise<BaasUser>`           | Read the signed-in user's profile.                        |
| `setEmail(email \| null): Promise<void>` | Set the signed-in user's email — pass `null` to clear it. |
| `addFcmToken(token): Promise<void>`      | Attach a push notification token.                         |
| `removeFcmToken(token): Promise<void>`   | Detach a push notification token.                         |

`getUser()` resolves to a `BaasUser`:

```ts
type BaasUser = {
  address:      string;                          // checksummed EVM address (the user id)
  email:        string | null;                   // profile email, or null if unset
  contractData: Record<string, unknown> | null;  // arbitrary contract-associated data
  fcmTokens:    string[];                        // registered push-notification tokens
  createdAt:    string;                          // ISO 8601 timestamp
};
```

Use `getUser()` when you need the full server-side profile. `baas.auth.getSession()` stays synchronous and returns only the local identity (the address and token).

{% hint style="info" %}
**No `userId` argument.** The SDK derives the user from the active session, so `getUser()` reads only that user (reading anyone else needs your secret key, server-side). If no one is signed in, every method throws `BaasAuthError('NOT_SIGNED_IN')` **synchronously**, before any network call. Input is validated **server-side**: invalid values throw `BaasApiError` with `.status === 400`, and the human-readable reason is in `err.body.detail`.
{% endhint %}

A couple of behaviours that are good to know:

* **FCM tokens are idempotent.** Adding a token that's already there, or removing one that isn't, is a no-op server-side, so it's safe to call these repeatedly without checking first.
* **Emails are normalized.** The server lowercases and trims the email, so `Alice@Example.com` is stored as `alice@example.com`.

## Handling errors

```ts
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) {
    showToast(err.body?.detail ?? 'Invalid email');
  }
}
```

## 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.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.baas.sh/baas-sdk/manage-user.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
