login

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

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

Parameters

This method has the following parameters:

Parameter

Description

Required

dbApiKey

String with database API key.

Yes.

username

String with user username.

Yes.

password

String with user password.

Yes.

masterKey

String with database master key, if specified than the password value is ignored.

No.

forcePassCheck

Boolean with database master key, forces checking the password value.

No.

Response

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

{
   "_id": <some_id>,
   "sessionToken": <session_token>
}
Examples

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.