Skip to content

Disable User

Description

This operation changes the user status to DISABLED.

This functionality can be used only in CloudCode (Java, JS or Codeless), the reason for this restriction is that a malicious use of this API can easily compromise application's security. As a result, this API must be used from a controlled environment.

Method

Backendless.UserService.disableUser(userId): Promise<void>;

where

Argument                Description
userId Unique identifier of the user account to be disabled. String value or number. Refer to the Data Import topic to learn more about objectId value as the number.

Return Value

None.

Example

The example below disables the user associated with the following objectId: "4D584E4D-05A3-4AC4-90C7-B80D1584E7AD".

const userObjectId = "4D584E4D-05A3-4AC4-90C7-B80D1584E7AD"

const onSuccessDisableUser = () => console.log('User disabled successfully')
const onError = error => console.error('Error: ', error)

// disable user account
Backendless.UserService.disableUser(userObjectId)
  .then(onSuccessDisableUser)
  .catch(onError)

Codeless Reference

user_service_codeless_set_user_status_as_disabled

where:

Argument                Description
id objectId/unique identifier of a user account to be disabled.

Important

This Codeless block is only available in CloudCode due to the security reasons. If this operation is exposed to users, then your application can be compromised.

This operation does not return a value.

Consider the following record in the Users data table:

user_service_codeless_example_set_user_status_as_enabled_disabled_common_example_2

Note that the userStatus column contains the current user status which is ENABLED.

The example below disables the user "alice@yourmail.com" associated with the objectId: "4D584E4D-05A3-4AC4-90C7-B80D1584E7AD".

user_service_codeless_example_set_user_status_as_disabled

After the Codeless logic runs, the user status successfully changes to DISABLED.

user_service_codeless_example_set_user_status_as_enabled_disabled_common_example