Skip to content

User Properties

When a user registers with an application, he provides information which establishes user's identity. For one application these properties may include name, phone number and email address, for another it could be user id, age and gender. Backendless User Service allows each application to have a custom set of properties associated with the user entity.

Defining properties with the API

User properties must be defined in the object representing a user. When user registers or user object is updated, Backendless saves the property values in the Users table of Backendless Data service. If a property is not declared on the server-side, Backendless automatically creates a definition for it. This behavior can be turned off/on using the Dynamic Schema Definition configuration setting in the console (select Data > Configuration). The setting is turned on by default:

dynamic-schema-definition.zoom70

Set/Update User Property

Important

When setting or updating a user property, the values must be of "primitive" data types (boolean, string, number, date). To assign a non-primitive value, use the Data relation API.

The following API can be used to set or update properties in a user object:

User properties can be set on an instance of the Backendless.User class. Setting a user property works the same as assigning any property of a JavaScript object. For example, the code below assigns a custom property phoneNumber:

var user = new Backendless.User();
user[ "phoneNumber" ] = "555-1212"

Retrieve User Property Values

User object properties can be retrieved using the same approach as with any JavaScript object. For example, the code below retrieves a a value for the phoneNumber property:

var phoneNumberValue = user[ "phoneNumber" ];

Example

The example below describes how to retrieve the phoneNumber user property.

Backendless.UserService.login( "spidey@backendless.com", "greeng0blin" )
   .then( function( loggedInUser ) {
      console.log( "User has been logged in: " + loggedInUser.email );

     var phoneNumber = loggedInUser[ "phoneNumber" ];
     console.log( "User phone number: + phoneNumber );
   });

Defining properties with Console

User property management is available in the schema editor of the Users table. To open the schema editor:

  1. Login to Backendless Console and select your application.
  2. Click the Data icon, and select the Users table.
  3. Click the Schema menu.

There are built-in user properties, such as email, name and password. The email and name properties can be deleted if they do not apply to your app, although it is recommended to keep the email property, since it is used for other purposes (for instance, password recovery). The password property cannot be deleted.

Identity Property

It is required that one of the properties is marked as identity. This is the property Backendless uses for the Login and Restore Password operations. As users register, Backendless ensures the value for the identity property is unique  in the context of a specific version of the application.

Password Property

"password" is a special property. Backendless automatically adds the property when an application is created. The following rules apply to the password property:

  • Password cannot be removed from the application.
  • Password cannot be used as identity.
  • Password is always a required property

users-schema.zoom80

To add a new property, click the New button.