Getting Started

Basics

Query Modifiers

.where() .sort()

Query Predicates

.equals() .notEquals() .exists() .notExists() .startsWith() .endsWith() .contains() .greaterThan() .lessThan() .between() .outside()

Query Executors

.read() .first() .last() .count() .sum() .average() .min() .max() .update() .delete()

Login Methods

.exists() .login() .logout()

Instance Methods

.read() .delete()

Instance Login Methods

.login() .logout() .changePassword()

Misc

Back.then() Back.saved() Back.user() Back.eachProperty() Back.eachDescendant() IFile Property LoginResult

ConstructorPlural.login()

Logs in an existing user. This method differs from the .login() method defined on the instance, which logs in a new user. Available when the constructor has at least one authentication method enabled in the editor. This method has a number of overloads which handle different login procedures.

Authenticating via email address and password

The first overload logins an existing user with an email address and a password. Typically this method would be called in the callback function of the .exists() method. In order for this function to succeed, the class must have Password Authentication set to on in the editor.

Employees.login("employee@company.com", "pass", employee =>
{
	var success = employee !== null;
});

Authenticating via OAuth

The second overload authenticates a user with an OAuth provider. In order for this function to succeed, the class must have one of the OAuth providers set to on in the editor. Authenticating with OAuth providers such as Facebook, Twitter, or Google+ tends to be a very awkward process. Each provider should provide a temporary token which then needs to be exchanged for a long-lived token. Consult the documentation for each provider for specifics on generating a temporary token. Once the temporary token is obtained, it is placed in an object with the exact structure as described below, and passed to the .login() method. Back I/O then handles the server-side token exchange.

var oauthResult = {
	shortCode: "FB", // Options are FB (Facebook), TW (Twitter), and IN (LinkedIn),
	temporaryToken: "token-from-provider-goes-here",
	redirectUri: "redirect-uri-used-goes-here"
};

Employees.login(oauthResult, (result, employee, accessToken) =>
{
	// If successful, employee will be an object of type Employee,
	// and accessToken will be a string containing the long-lived
	// token received from the OAuth provider that may be used
	// to make provider-specific API calls.
});

Authenticating via "Login From Inbox"

The third overload is for a special Back I/O feature called "Login From Inbox". This feature allows a user to authenticate by clicking a link in an email sent to their inbox, rather than providing a password. This feature can be used to support password resetting in the event of a password loss, signup invitations, and more.

var loginFromInboxOptions = {
	// Required parameters
	email: "employee@company.com",
	url: "http://www.company.com/click-through-url-in-email-goes-here",
	
	// Optional parameters
	subject: "Reset your password",
	body: "Please click the link below to reset your password"
};

Employees.login(loginFromInboxOptions, result =>
{
	if (result === Back.LoginResult.success)
		alert("Login email successfully sent");
});

Capturing the authenticated user

The fourth overload takes only a single callback argument, and returns the currently authenticated user.

Employees.login(employee =>
{
	// If the current user is authenticated as an Employee
	// the employee argument will contain the user instance.
	// Otherwise, it will be null.
});