> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getmilana.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Update User

> Update profile fields for the session's user with updateUser().

Call `updateUser()` to update profile fields (name, email, metadata) for the user attached to the current session. Use this for partial user updates as context evolves during the session — e.g. the user upgrades their plan, switches teams, or completes onboarding.

User metadata has upsert semantics across the user's lifetime: any fields you provide are merged with previously set values, so you only need to send what has changed.

<Tip>
  `updateUser()` does not re-attribute an already-identified session. Once a session is linked to a user (via the first `identify` or `updateUser` call), subsequent `updateUser` calls with a different `userId` will not move the session to a different user — they only update the named user's metadata.

  For the initial "user just signed in" flow with a known email, [`identify()`](/sdk/identify) is the more focused entry point. For session-level metadata, use [`updateSession()`](/sdk/update-session).
</Tip>

<Tabs>
  <Tab title="React">
    Use the `useMilana()` hook:

    ```tsx theme={null}
    import { useMilana } from "milana-js/react";

    function UpgradeButton() {
      const { updateUser } = useMilana();

      const handleUpgrade = async (newPlan: string) => {
        await billing.upgrade(newPlan);
        void updateUser({
          userId: currentUser.id,
          metadata: { plan: newPlan },
        });
      };

      return <button onClick={() => handleUpgrade("pro")}>Upgrade</button>;
    }
    ```
  </Tab>

  <Tab title="JavaScript">
    ```typescript theme={null}
    import { updateUser } from "milana-js";

    await updateUser({
      userId: "usr_12345",
      metadata: {
        plan: "pro",
        role: "admin",
      },
    });
    ```
  </Tab>

  <Tab title="Script Tag">
    ```javascript theme={null}
    Milana("updateUser", {
      userId: "usr_12345",
      metadata: {
        plan: "pro",
        role: "admin",
      },
    });
    ```
  </Tab>
</Tabs>

***

## Parameters

<ParamField path="userId" type="string" required>
  A stable, unique identifier for the user in your system. Use your database user ID or a similar permanent identifier — do not use an email address as the primary ID. Pass the same `userId` as your prior `identify` call; a different `userId` will not re-attribute the session.
</ParamField>

<ParamField path="email" type="string">
  The user's email address. Used to connect user identity across your systems (e.g. support tools, CRM, data warehouse) and displayed in the dashboard.
</ParamField>

<ParamField path="name" type="string">
  The user's display name.
</ParamField>

<ParamField path="metadata" type="object">
  Arbitrary key-value pairs to attach to the user. Keys are strings, values can be `string`, `number`, `boolean`, `null`, or nested objects/arrays of the same types. e.g. `plan`, `team`, `country`, `role`, `accountType`.
</ParamField>

## Return value

<ResponseField name="success" type="boolean">
  `true` if the update was applied. `false` if the session was not active, the network request failed, or the session was not sampled.
</ResponseField>

## Timing

`updateUser()` is safe to call before `init()` completes — the SDK queues the call and replays it once the session is ready.
