User Management

Introduction

Turbo projects support user management out of the box. Each user comes with convetional properties: firstName, lastName, email, password, username.

USER Schema

PropertyTypeRequiredDescription
firstNameStringFalseFirst name of user.
lastNameStringFalseLast name of user.
emailStringFalseEmail address of user.
usernameStringFalseUsername for user. Does not have to be unique.
imageStringFalseURL of the primary image for the user.
bioStringFalseUser biography or description.
passwordStringTrueUser password. Automatically encrypted in Datastore on creation. Every login requires password.

Projects can add custom properties by simply including them as parameters during creation. For example, if your project requires a 'company' field for users, simply add {company: 'COMPANY_NAME_OR_ID'} to the parameters when creating new users.


Creating Users

To create a user, call the createUser(params, completion) function from the Turbo SDK which takes a parameters JSON argument as well as a callback:

..assets/js/app.js

The user above will be populated with the specified fields and the password will be hashed automatically. If you want to add a custom field, simply include it with the JSON parameters (e.g. "{position: 'guard'}") and it will save with the other properties. The 'data' argument in the callback returns the created user properties as a JSON object without the password.


Log In / Log Out

To log users in, call the login(credentials, completion) function from the Turbo SDK. The 'credentials' argument is a JSON object containing the user's password and one other defining attribute such as 'username' or 'email.' The other attribute can be anything but we strongly recommend username or email:

..assets/js/app.js

If the login is not successful, the 'err' object is populated with a message describing the issue (wrong password, user not found etc). If login is successful, Turbo tracks the logged-in user which persists across sessions. To check the currently logged-in user, if any, call the currentUser(completion) function from the Turbo SDK:

..assets/js/app.js

If there is no current user logged in, the 'err' object will be populated. Otherwise, the 'data' argument will return with basic information about the user. To log a user out, call the logout(completion) function:

..assets/js/app.js

Even on success, the 'data' argument is null in the completion.


Updating Users

Updating users is done through the same method as updating any other resource on Turbo. The following arguments are required to update: resource name ('user' in this case), original user, updated parameters, and completion:

..assets/js/app.js

Note that the updatedUser argument only contains the fields to be changed. All other fields will remain the same. The originalUser argument is the user before any changes take place and should be obtained via the currentUser() method.


Deleting Users

Removing users is done through the same method as removing any other resource on Turbo. The following arguments are required to delete: resource name ('user' in this case), user object, and completion:

..assets/js/app.js

The currentUser argument is the user to be removed.


Questions/Comments

If you have any questions, comments or feedback, feel free to contact us at matthew@turbo360.co