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

# Users

> Learn how to manage your users with QuickBlox.

Visit [Key Concepts](/docs/key-concepts) page to learn the most important QuickBlox concepts.

## Before you begin

1. Register a [QuickBlox account](https://admin.quickblox.com/signin). This is a matter of a few minutes and you will be able to use this account to build your apps.
2. Configure QuickBlox SDK for your app. Check out [Setup](/sdks/react-native-setup) page for more details.
3. Create a user session to be able to use QuickBlox functionality. See [Authentication](/sdks/react-native-authentication) page to learn how to do it.

## Create user

It's recommended to manage user creation at your backend for production. To learn more you can refer to [QuickBlox API documentation](https://docs.quickblox.com/reference/create-user).

For POCs/MVPs or during development you may want to create users on the fly, you can use `create()` method.

Create a user using the code snippet below. Only login (or email) and password are required. Other fields are optional.

```JavaScript JavaScript theme={null}
const createUserParams = {
  email: '[[email protected]](/cdn-cgi/l/email-protection)',
  fullName: 'Jack Sparrow',
  login: 'jack',
  password: 'jackpassword',
  phone: '404-388-5366',
  tags: ['awesome', 'quickblox']
};

QB.users
  .create(createUserParams)
  .then(function (user) {
    // user created successfully
  })
  .catch(function (e) {
    // handle as necessary
  });
```

<Warning>
  **Security & Privacy**

  It's recommended to [disable permission](/docs/application#set-session-permissions) to create users with application session on **production apps** once user creation is implemented on your backend.

  Email, full name, facebookId and phone number are PII, [configure session permissions](/docs/application#set-session-permissions) according to your privacy requirements.
</Warning>

## Retrieve users

Get a list of users using the `getUsers()` method below. The code snippet below shows how to get a list of users with `full_name` containing `John`, sorted by the `updated_at` field in descending order, and limited to 10 users on the page.

```JavaScript JavaScript theme={null}
// * @param {Object} result
// * @param {QBUser[]} result.users Array of users returned from API request
// * @param {number} result.page Page of results
// * @param {number} result.perPage How much items returned per page
// * @param {number} result.total Total amount of results

function processUsers(result) {
  //
}

const filter = {
  field: QB.users.USERS_FILTER.FIELD.FULL_NAME,
  type: QB.users.USERS_FILTER.TYPE.STRING,
  operator: QB.users.USERS_FILTER.OPERATOR.IN,
  value: 'John'
};

const sort = {
  ascending: false,
  field: QB.users.USERS_SORT.FIELD.LAST_REQUEST_AT,
  type: QB.users.USERS_SORT.TYPE.STRING
};

const getUsersQuery = {
  filter: filter,
  sort: sort,
  page: 1,
  perPage: 10
};

QB.users
  .getUsers(getUsersQuery)
  .then(processUsers)
  .catch(function (error) {
    // handle error
  });
```

The method `getUsers()` accepts one (optional) argument of the object type that has the following fields:

| Field   | Required | Desription                                   |
| ------- | -------- | -------------------------------------------- |
| filter  | no       | Specifies filtering criteria for the field.  |
| sort    | no       | Specifies sorting criteria for the field.    |
| page    | no       | Number of pages with results to be returned. |
| perPage | no       | Number of records to return in one page.     |

If you want to retrieve only users updated after some specific date time, you can use operators. This is useful if you cache users somehow and do not want to obtain the whole list of your users on every app start. Thus, you can use [search operators](/sdks/react-native-users#search-operators) and [sort operators](/sdks/react-native-users#sort-operators) to list users on the page so that it is easier to see specific users.

### Search operators

You can use search operators to get more specific search results. The request below will return users filtered by IDs.

```JavaScript JavaScript theme={null}
const occupantsIds = dialog.occupantsIds;
const filter = {
  field: QB.users.USERS_FILTER.FIELD.ID,
  type: QB.users.USERS_FILTER.TYPE.NUMBER,
  operator: QB.users.USERS_FILTER.OPERATOR.IN,
  value: occupantsIds.join() // value should be of type String
};

const getUsersQuery = {
  filter: filter
};

function processUsers(result) {}

QB.users
  .getUsers(getUsersQuery)
  .then(processUsers)
  .catch(function (e) {
    // handle error
  });
```

Here are the search operators that you can use to search for the exact data that you need.

| Search operators | Applicable to types  | Applicable to fields                                                                                               | Description                                |
| ---------------- | -------------------- | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------ |
| lt               | number, string, date | id, created\_at, updated\_at, last\_request\_at, external\_user\_id, facebook\_id                                  | **Less Than** operator.                    |
| ge               | number, string, date | id, created\_at, updated\_at, last\_request\_at, external\_user\_id, facebook\_id                                  | **Greater Than** or **Equal** to operator. |
| gt               | number, string, date | id, created\_at, updated\_at, last\_request\_at, external\_user\_id, facebook\_id                                  | **Greater Than** operator.                 |
| le               | number, string, date | id, created\_at, updated\_at, last\_request\_at, external\_user\_id, facebook\_id                                  | **Less or Equal to** operator              |
| eq               | number, string, date | id, full\_name, email, login, phone, created\_at, updated\_at, last\_request\_at, external\_user\_id, facebook\_id | **Equal** to operator.                     |
| ne               | number, string, date | id, full\_name, email, login, phone, created\_at, updated\_at, last\_request\_at, external\_user\_id, facebook\_id | **Not Equal** to operator.                 |
| between          | number, string, date | id, created\_at, updated\_at, last\_request\_at, external\_user\_id, facebook\_id                                  | **Contained between values** operator.     |
| in               | number, string, date | id, full\_name, email, login, phone, created\_at, updated\_at, last\_request\_at, external\_user\_id, facebook\_id | **IN** array operator.                     |

### Sort operators

You can use sort operators to order the search results. The request below will return users sorted in descending order by the last date a user was requested.

```JavaScript JavaScript theme={null}
const sort = {
  ascending: false,
  field: QB.users.USERS_SORT.FIELD.LAST_REQUEST_AT,
  type: QB.users.USERS_SORT.TYPE.STRING
};

const getUsersQuery = {
  sort: sort
};

function processUsers(result) {}

QB.users
  .getUsers(getUsersQuery)
  .then(processUsers)
  .catch(function (e) {
    // handle error
  });
```

Here are the sort options that you can use to order the search results:

| Sort options | Applicable to types  | Applicable to fields                                                                                          | Description                                                            |
| ------------ | -------------------- | ------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |
| ascending    | All types            | id, full\_name, email, login, phone, website, created\_at, updated\_at,last\_request\_at, external\_user\_id  | Sort results in the ascending order by setting the ascending as true.  |
| descending   | All types            | id, full\_name, email, login, phone, website, created\_at, updated\_at,last\_request\_at, external\_user\_id  | Sort results in the ascending order by setting the ascending as false. |
| field        | String, Number, Date | id, full\_name, email, login, phone, website, created\_at, updated\_at, last\_request\_at, external\_user\_id | Sort Field Value                                                       |
| type         | String, Number, Date | id, full\_name, email, login, phone, website, created\_at, updated\_at, last\_request\_at, external\_user\_id | Type of Sort Field Value                                               |

## Reset user password

<Note>
  This feature is coming soon. Please check back later. For more updates and questions, feel free to contact our [Customer Support Team](https://help.quickblox.com/).
</Note>

## Update user

Update a user profile by calling the `update()` method. If you want to change your password, you need to provide 2 parameters: `password` and `newPassword`. As a result, the updated user entity will be returned.

You can update any other field of the user using the `updateUser()` method. Thus, the snippet below shows how to update a `tagList` and `customData` fields.

```JavaScript JavaScript theme={null}
const updateUserParams = {
  customData: JSON.stringify({
    name: 'John',
    age: 31,
    city: 'New York'
  }),
  tags: ['testOne', 'tagTwo']
};

QB.users
  .update(updateUserParams)
  .then(function (updatedUser) {
    // update local user information with the data server returned
  })
  .catch(function (e) {
    // handle error
  });
```

The `update()` method accepts one argument of the object type that has the following fields:

| Field      | Required | Description                                                                                                                                                                                                                                                                                                                                                                    |
| ---------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| customData | no       | User custom data. Should be a String. You can convert any data types to String. For example, JSON, XML, etc.                                                                                                                                                                                                                                                                   |
| tags       | no       | User tags. An array of Strings. A tag must include alphanumeric characters only and start with a letter. There are no spaces in the tag format. For example, the "tagOne" format is correct while the "tag one" format is incorrect. The maximum number of tags is 10. If more that 10 tags are provided, an error is returned: Error: tag list should contain maximum 10 tags |

## Set user avatar

To set a user avatar, just upload a file to the QuickBlox cloud storage and connect it to the user.

To upload the file to the QuickBlox cloud storage, call the `upload()` method and pass the `fileUrl` to it. The `fileUrl` is a path to the file in the device filesystem. Now that the file is uploaded, get the ID of the uploaded file.

To connect the file to the user, set the ID of the uploaded file to the `blobId` field of the `user` and call the `update()` method. As a result, the user avatar gets updated.

```JavaScript JavaScript theme={null}
const fileUrl = "path to file in device's filesystem";
const contentUploadParams = {
  url: fileUrl,
  public: false
};

QB.content
  .upload(contentUploadParams)
  .then(function (file) {
    // file uploaded successfully
    const updateUserParams = { blobId: file.id };
    return QB.users.update(updateUserParams);
  })
  .then(function (user) {
    // user updated successfully
  })
  .catch(function (error) {
    // inspect error message to check what is wrong
  });
```

The `update()` method accepts one argument of the object type that has the following fields:

| Field  | Required | Description   |
| ------ | -------- | ------------- |
| blobId | no       | User blob ID. |

## Get user avatar

You can also get access to the uploaded avatar of the user by calling the `getPrivateURL()` method. As a result, you will receive a private URL in the response. See [this section](/sdks/react-native-content) to learn more about file URLs and `getInfo()` method.

```JavaScript JavaScript theme={null}
const contentGetInfoParams = {
  id: user.blobId
};

// get access to the avatar that was set in user's "blobId" property
QB.content
  .getInfo(contentGetInfoParams)
  .then(function (file) {
    const contentGetPrivateUrlParams = { uid: file.uid };
    return QB.content.getPrivateUrl(contentGetPrivateUrlParams);
  })
  .then(function (imageUrl) {
    // <Image source={{ uri: imageUrl }}/>
  })
  .catch(function (error) {
    // inspect error message to check what is wrong
  });
```

The `getPrivateUrl()` method accepts one argument of the object type that has the following fields:

| Field | Required | Description               |
| ----- | -------- | ------------------------- |
| uid   | yes      | A file unique indetifier. |
