DatabaseUser.login(dbApiKey, username, password[, masterApiKey])

Logs a user into the database, returns a session token which is then used to invoke other APIs.


This method has the following parameters:

dbApiKeyString with database API key.Yes.
usernameString with user username.Yes.
passwordString with user password.Yes.
masterKeyString with database master key, if specified than the password value is ignored.No.
forcePassCheckBoolean with database master key, forces checking the password value.No.


The method will return the user ID and the user's session token.

   "_id": <some_id>,
   "sessionToken": <session_token>

User Sign-in

In this example a user signs into the database:

var dbApiKey = "57928860e4b00ef864f3dc24"
var username = "amy";
var password = "123";

var result = DatabaseUser.login(dbApiKey, username, password);
Apperyio.response.success(result, "application/json");
    "sessionToken": "5220005e-7a53-4200-9dcc-0156b9793be0",
    "_id": "5797dfd5e4b0264ccd2efde6"
Getting the Session Token

You can also get the token directly using this code:

var token = DatabaseUser.login(dbApiKey, username, password).sessionToken;
Using the Master Key

The Master key allows you to sign in without providing a password:

var dbApiKey = "57928860e4b00ef864f3dc24"
var masterKey = "590e43a0-d15e-4f24-a944-8f30d914ca8f";
var username = "amy";
var password = "123";

var token = DatabaseUser.login(dbApiKey, username, null, masterKey).sessionToken;


Using the Master Key

The Master key gives you admin access to the database. This means you can view, edit and delete any data. Use it only when necessary.