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

# Refresh User Data

# refreshUser

Refreshes the current user's data from the server. This function fetches the latest authenticated user information from the backend and updates the local user state.

Use this when you need to ensure the user's profile data is synchronized with the server, such as after making changes to the user's account information.

## Usage

```javascript theme={"system"}
import { refreshUser } from '@dynamic-labs-sdk/client';

const updateUserData = async () => {
  const user = await refreshUser();
  console.log('User refreshed:', user);
};
```

## Parameters

| Parameter | Type                       | Description                                                             |
| --------- | -------------------------- | ----------------------------------------------------------------------- |
| `client`  | `DynamicClient` (optional) | The Dynamic client instance. Only required when using multiple clients. |

## Returns

`Promise<SdkUser>` - A promise that resolves to the authenticated user object with updated data.

## Examples

### Basic usage

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={"system"}
    import { refreshUser } from '@dynamic-labs-sdk/client';

    const handleProfileUpdate = async () => {
      // After updating user profile on the backend
      await updateUserProfile();

      // Refresh user to get the latest data
      const updatedUser = await refreshUser();
      console.log('Updated user:', updatedUser);
    };
    ```
  </Tab>

  <Tab title="React">
    ```tsx theme={"system"}
    import { refreshUser } from '@dynamic-labs-sdk/client';

    function ProfileUpdateButton() {
      const handleUpdate = async () => {
        await updateUserProfile();
        await refreshUser();
        // userChanged fires — any useUser() consumers re-render automatically
      };

      return <button onClick={handleUpdate}>Sync profile</button>;
    }
    ```
  </Tab>
</Tabs>

### Listen to user changes

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={"system"}
    import { refreshUser, onEvent } from '@dynamic-labs-sdk/client';

    onEvent({
      event: 'userChanged',
      listener: ({ user }) => {
        console.log('User data updated:', user);
      },
    });

    await refreshUser();
    ```
  </Tab>

  <Tab title="React">
    Components using `useUser()` re-render automatically when `userChanged` fires — no manual listener needed. If you need a side-effect on change, register it once at app level.

    ```tsx theme={"system"}
    import { useOnEvent } from '@dynamic-labs-sdk/react-hooks';

    function useUserChangeLogger() {
      useOnEvent({
        event: 'userChanged',
        listener: ({ user }) => console.log('User updated:', user),
      });
    }
    ```
  </Tab>
</Tabs>

### Handle wallet account changes

<Tabs>
  <Tab title="JavaScript">
    ```javascript theme={"system"}
    import { refreshUser, onEvent } from '@dynamic-labs-sdk/client';

    onEvent({
      event: 'walletAccountsChanged',
      listener: ({ walletAccounts }) => {
        console.log('Wallet accounts updated:', walletAccounts);
      },
    });

    await refreshUser();
    ```
  </Tab>

  <Tab title="React">
    Components using `useGetWalletAccounts()` re-render automatically when `walletAccountsChanged` fires after a `refreshUser()` call.
  </Tab>
</Tabs>
