Backendless Support
 

Required user properties for user registrations

When registering a user an app sends to the server a collection of user registration properties. Values for these properties typically come from a registration form in the app. Some form fields may be required and have a special validation logic. 

To assist with these use-cases Backendless provides a very simple way to enforce these rules on the backend. 

This topic covers the issue of configuring registration properties as required. Once it is done, any registration API request which does not include a required property is rejected by the server with an error.

To configure a property as required it necessary to follow the next steps:

  1. Login to Backendless console, select an app and click the Users icon.
  2. The User Properties menu is selected by default. You should see a list of user properties:
  3. Notice the Required column which is rendered with a checkbox for each property. Click a checkbox marks the property as required.

For instance, in the interface above if one selects the "name" property as required and runs the following code, the server would respond with an error. 

NOTICE: the line of code which sets the "name" property is commented out to cause an error.
Asynchronous Code (Plain Java and Android):
private static void registerUserAsync()
{
 Calendar calendar = Calendar.getInstance();
 calendar.set( 1980, 5, 12 );
 Date birthDate = calendar.getTime();
 BackendlessUser user = new BackendlessUser();
 user.setEmail( "spiderman@backendless.com" );
 user.setPassword( "greeng0blin" );
 //user.setProperty( "name", "Spidey" );
 Backendless.UserService.register( user, new AsyncCallback<BackendlessUser>()
 {
 @Override
 public void handleResponse( BackendlessUser backendlessUser )
 {
 System.out.println( "user has been registered" );
 }
 @Override
 public void handleFault( BackendlessFault backendlessFault )
 {
 System.out.println( "server reported an error - " + backendlessFault.getMessage() );
 }
 } );
}
Synchronous Code (Plain Java only):
private static void registerUserSync()
{
 Calendar calendar = Calendar.getInstance();
 calendar.set( 1980, 5, 12 );
 Date birthDate = calendar.getTime();
 BackendlessUser user = new BackendlessUser();
 user.setEmail( "spiderman@backendless.com" );
 user.setPassword( "greeng0blin" );
 //user.setProperty( "name", "Spidey" );
 Backendless.UserService.register( user );
}
Reported error:
Unable to register user. Property 'name' is required

As soon as the line of code which sets the "name" property is included into the code, the error goes away and the user is successfully created.

Review related topics:

Is article helpful?