Class: LoopBackApplication Static Methods

app.connector(name, connector)

Register a connector.

When a new data-source is being added via app.dataSource, the connector
name is looked up in the registered connectors first.

Connectors are required to be explicitly registered only for applications
using browserify, because browserify does not support dynamic require,
which is used by LoopBack to automatically load the connector module.

Arguments

Name

Type

Description

name

String

Name of the connector, e.g. 'mysql'.

connector

Object

Connector object as returned by require('loopback-connector-{name}').

app.dataSource(name, config)

Define a DataSource.

Arguments

Name

Type

Description

name

String

The data source name

config

Object

The data source config

app.enableAuth()

Enable app wide authentication.

app.listen([cb])

Listen for connections and update the configured port.

When there are no parameters or there is only one callback parameter,
the server will listen on app.get('host') and app.get('port').

For example, to listen on host/port configured in app config:

app.listen();

Otherwise all arguments are forwarded to http.Server.listen.

For example, to listen on the specified port and all hosts, and ignore app config.

app.listen(80);

The function also installs a listening callback that calls
app.set('port') with the value returned by server.address().port.
This way the port param contains always the real port number, even when
listen was called with port number 0.

Arguments

Name

Type

Description

[cb]

Function

If specified, the callback is added as a listener for the server's "listening" event.

Returns

Name

Type

Description

result

http.Server

A node http.Server with this application configured as the request handler.

app.model(Model, config)

Attach a model to the app. The Model will be available on the
app.models object.

Example - Attach an existing model:

var User = loopback.User;
app.model(User);

Example - Attach an existing model, alter some aspects of the model:

var User = loopback.User;
app.model(User, { dataSource: 'db' });

Arguments

Name

Type

Description

Model

Object

The model to attach.

config

Object

The model's configuration.

config

Name

Type

Description

dataSource

String or DataSource

The DataSource to which to attach the model.

[public]

Boolean

Whether the model should be exposed via REST API.

[relations]

Object

Relations to add/update.

Returns

Name

Type

Description

result

ModelConstructor

the model class

app.models()

Get the models exported by the app. Returns only models defined using app.model()

Path to a default favicon shipped with LoopBack. Use as follows: app.use(require('serve-favicon')(loopback.faviconFile));

Class: loopback Static Methods

loopback.configureModel(ModelCtor, config)

Alter an existing Model class.

Arguments

Name

Type

Description

ModelCtor

Model

The model constructor to alter.

config

Object

Additional configuration to apply

config

Name

Type

Description

dataSource

DataSource

Attach the model to a dataSource.

[relations]

Object

Model relations to add/update.

loopback.createDataSource(name, options)

Create a data source with passing the provided options to the connector.

Arguments

Name

Type

Description

name

String

Optional name.

options

Object

Data Source options

options

Name

Type

Description

connector

Object

LoopBack connector.

[*]

Other connector properties. See the relevant connector documentation.

loopback.createModel

Create a named vanilla JavaScript class constructor with an attached
set of properties and options.

This function comes with two variants:

loopback.createModel(name, properties, options)

loopback.createModel(config)

In the second variant, the parameters name, properties and options
are provided in the config object. Any additional config entries are
interpreted as options, i.e. the following two configs are identical:

registry.createDataSource(name, options)

Create a data source with passing the provided options to the connector.

Arguments

Name

Type

Description

name

String

Optional name.

options

Object

Data Source options

options

Name

Type

Description

connector

Object

LoopBack connector.

[*]

Other connector properties. See the relevant connector documentation.

loopback.createModel

Create a named vanilla JavaScript class constructor with an attached
set of properties and options.

This function comes with two variants:

loopback.createModel(name, properties, options)

loopback.createModel(config)

In the second variant, the parameters name, properties and options
are provided in the config object. Any additional config entries are
interpreted as options, i.e. the following two configs are identical:

The method can either be called with the following signature or with a single
argument: an AccessRequest instance or an object containing all the required properties.

Arguments

Name

Type

Description

model|req

String or AccessRequest or Object

The model name, or an AccessRequest instance/object.

property

String

The property/method/relation name

accessType

String

The access type

permission

String

The requested permission

methodNames

Array.<String>

The names of involved methods

registry

Registry

The application or global registry

Returns

Name

Type

Description

result

AccessRequest

Class: AccessRequest Instance Methods

accessRequest.exactlyMatches(acl)

Does the given ACL apply to this AccessRequest.

Arguments

Name

Type

Description

acl

ACL

accessRequest.isAllowed()

Is the request for access allowed?

Returns

Name

Type

Description

result

Boolean

accessRequest.isWildcard()

Does the request contain any wildcards?

Returns

Name

Type

Description

result

Boolean

accessRequest.settleDefaultPermission(defaultPermission)

Settle the accessRequest's permission if DEFAULT
In most situations, the default permission can be resolved from the nested model
config. An default permission can also be explicitly provided to override it or
cope with AccessRequest instances without a nested model (e.g. model is '*')

Arguments

Name

Type

Description

defaultPermission

String

(optional) the default permission to apply

Class: Principal(type, id, [name], modelName)

This class represents the abstract notion of a principal, which can be used
to represent any entity, such as an individual, a corporation, and a login id

Arguments

Name

Type

Description

type

String

The principal type

id

The principal id

[name]

String

The principal name

modelName

String

The principal model name

Returns

Name

Type

Description

result

Principal

Class: Principal Instance Methods

principal.equals(p)

Compare if two principals are equal
Returns true if argument principal is equal to this principal.

Model.setup()

The loopback.Model.extend() method calls this when you create a model that extends another model.
Add any setup or configuration code you want executed when the model is created.
See Setting up a custom model.

PersistedModel.findOrCreate([filter], data, callback)

Finds one record matching the optional filter object. If not found, creates
the object using the data provided as second argument. In this sense it is
the same as find, but limited to one object. Returns an object, not
collection. If you don't provide the filter object argument, it tries to
locate an existing object that matches the data argument.

PersistedModel.upsertWithWhere([where], data, callback)

Update or insert a model instance based on the search criteria.
If there is a single instance retrieved, update the retrieved model.
Creates a new model if no model instances were found.
Returns an error if multiple instances are found.

Class: PersistedModel Instance Methods

persistedModel.destroy(callback)

Deletes the model from persistence.
Triggers destroy hook (async) before and after destroying object.

Arguments

Name

Type

Description

callback

Function

Callback function.

persistedModel.fillCustomChangeProperties(callback)

Add custom data to the Change instance.

Models should override this function to duplicate model instance properties
to the Change instance properties, typically to allow the changes() method
to filter the changes using these duplicated properties directly while
querying the Change model.

persistedModel.setId(val)

Set the correct id property for the PersistedModel. Uses the setId method if the model is attached to
connector that defines it. Otherwise, uses the default lookup.
Override this method to handle complex IDs.

Arguments

Name

Type

Description

val

The id value. Will be converted to the type that the id property specifies.

persistedModel.updateAttribute(name, value, callback)

Update a single attribute.
Equivalent to updateAttributes({name: 'value'}, cb)

Each option array is used to add additional keys to find an accessToken for a request.

[options]

Name

Type

Description

[cookies]

Array

Array of cookie names.

[headers]

Array

Array of header names.

[params]

Array

Array of param names.

[searchDefaultTokenKeys]

Boolean

Use the default search locations for Token in request

[enableDoublecheck]

Boolean

Execute middleware although an instance mounted earlier in the chain didn't find a token

[overwriteExistingToken]

Boolean

only has effect in combination with enableDoublecheck. If truthy, will allow to overwrite an existing accessToken.

[model]

Function or String

AccessToken model name or class to use.

[currentUserLiteral]

String

String literal for the current user.

[bearerTokenBase64Encoded]

Boolean

Defaults to true. For Bearer token based Authorization headers, decode the value from Base64. If set to false, the decoding will be skipped and the token id will be the raw value
parsed from the header.

loopback.urlNotFound()

Convert any request not handled so far to a 404 error
to be handled by error-handling middleware.

Built-in models

Class: AccessToken

AccessToken

Token based authentication and access control.

Default ACLs

DENY EVERYONE *

ALLOW EVERYONE create

Class Properties

Name

Type

Description

id

String

Generated token ID.

ttl

Number

Time to live in seconds, 2 weeks by default.

created

Date

When the token was created.

settings

Object

Extends the Model.settings object.

settings.accessTokenIdLength

Number

Length of the base64-encoded string access token. Default value is 64. Increase the length for a more secure access token.

Class: AccessToken Static Methods

AccessToken.createAccessTokenId(callback)

Create a cryptographically random access token id.

Arguments

Name

Type

Description

callback

Function

Callback

Name

Type

Description

err

Error

token

String

AccessToken.findForRequest(req, [options], callback)

Find a token for the given ServerRequest.

Arguments

Name

Type

Description

req

ServerRequest

[options]

Object

Options for finding the token

callback

Function

Callback

Name

Type

Description

err

Error

token

AccessToken

AccessToken.getIdForRequest(req, [options])

Extract the access token id from the HTTP request

Arguments

Name

Type

Description

req

Request

HTTP request object

[options]

Object

Each option array is used to add additional keys to find an accessToken for a request.

[options]

Name

Type

Description

[cookies]

Array

Array of cookie names.

[headers]

Array

Array of header names.

[params]

Array

Array of param names.

[searchDefaultTokenKeys]

Boolean

Use the default search locations for Token in request

[bearerTokenBase64Encoded]

Boolean

Defaults to true. For Bearer token based Authorization headers, decode the value from Base64. If set to false, the decoding will be skipped and the token id will be the raw value
parsed from the header.

AccessToken.resolve(id, cb)

Resolve and validate the access token by id

Arguments

Name

Type

Description

id

String

Access token

cb

Function

Callback function

Callback

Name

Type

Description

err

Error

Error information

Resolved

Object

access token object

Class: AccessToken Instance Methods

accessToken.validate(callback)

Validate the token.

Arguments

Name

Type

Description

callback

Function

Callback

Name

Type

Description

err

Error

isValid

Boolean

Class: ACL

ACL

A Model for access control meta data.

System grants permissions to principals (users/applications, can be grouped
into roles).

Whether to use production Apple Push Notification Service (APNS) servers to send push notifications. If true, uses gateway.push.apple.com:2195 and feedback.push.apple.com:2196.
If false, uses gateway.sandbox.push.apple.com:2195 and feedback.sandbox.push.apple.com:2196

Class: Application Static Methods

Application.authenticate(appId, key, callback)

Optional callback. When the callback function is not provided,
a promise is returned instead (see below).

Name

Type

Description

err

Error

matched

String

The matching key; one of: - clientKey

javaScriptKey

restApiKey

windowsKey

masterKey

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

Handler

Argument

Description

resolve

String

The matching key; one of: - clientKey

javaScriptKey

restApiKey

windowsKey

masterKey

Application.register(owner, name, options, callback)

Register a new application

Arguments

Name

Type

Description

owner

String

Owner's user ID.

name

String

Name of the application

options

Object

Other options

callback

Function

Callback function

Callback (optional)

Optional callback. When the callback function is not provided,
a promise is returned instead (see below).

Name

Type

Description

err

Error

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

Handler

Argument

Description

resolve

undefined

The resolve handler does not receive any arguments.

Application.resetKeys(appId, callback)

Reset keys for a given application by the appId

Arguments

Name

Type

Description

appId

Any

callback

Function

Callback (optional)

Optional callback. When the callback function is not provided,
a promise is returned instead (see below).

Name

Type

Description

err

Error

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

Handler

Argument

Description

resolve

undefined

The resolve handler does not receive any arguments.

Class: Application Instance Methods

application.resetKeys(callback)

Reset keys for the application instance

Arguments

Name

Type

Description

callback

Function

Callback

Name

Type

Description

err

Error

Class: Change

Change

Change list entry.

Class Properties

Name

Type

Description

id

String

Hash of the modelName and ID.

rev

String

The current model revision.

prev

String

The previous model revision.

checkpoint

Number

The current checkpoint at time of the change.

modelName

String

Model name.

modelId

String

Model ID.

settings

Object

Extends the Model.settings object.

settings.hashAlgorithm

String

Algorithm used to create cryptographic hash, used as argument to crypto.createHash. Default is sha1.

settings.ignoreErrors

Boolean

By default, when changes are rectified, an error will throw an exception. However, if this setting is true, then errors will not throw exceptions.

Class: Change Static Methods

Change.bothDeleted(a, b)

Are both changes deletes?

Arguments

Name

Type

Description

a

Change

b

Change

Change.diff(modelName, since, remoteChanges, callback)

Determine the differences for a given model since a given checkpoint.

The callback will contain an error or result.

result

{
deltas: Array,
conflicts: Array
}

deltas

An array of changes that differ from remoteChanges.

conflicts

An array of changes that conflict with remoteChanges.

Arguments

Name

Type

Description

modelName

String

since

Number

Compare changes after this checkpoint

remoteChanges

Array.<Change>

A set of changes to compare

callback

Function

Callback

Name

Type

Description

err

Error

result

Object

See above.

Change.findOrCreateChange(modelName, modelId, callback)

Find or create a change for the given model.

Arguments

Name

Type

Description

modelName

String

modelId

String

callback

Function

Callback

Name

Type

Description

err

Error

change

Change

Change.getCheckpointModel()

Get the checkpoint model.

Change.hash(str)

Create a hash of the given string with the options.hashAlgorithm.
Default: sha1

Arguments

Name

Type

Description

str

String

The string to be hashed

Change.idForModel(modelName, modelId)

Get an identifier for a given model.

Arguments

Name

Type

Description

modelName

String

modelId

String

Change.rectifyAll(cb)

Correct all change list entries.

Arguments

Name

Type

Description

cb

Function

Change.rectifyModelChanges(modelName, modelIds, callback)

Track the recent change of the given modelIds.

Arguments

Name

Type

Description

modelName

String

modelIds

Array

callback

Function

Callback

Name

Type

Description

err

Error

changes

Array

Changes that were tracked

Change.revisionForInst(inst)

Get the revision string for the given object

Arguments

Name

Type

Description

inst

Object

The data to get the revision string for

Class: Change Instance Methods

change.conflictsWith(change)

Does this change conflict with the given change.

Arguments

Name

Type

Description

change

Change

change.currentRevision(callback)

Get a change's current revision based on current data.

Arguments

Name

Type

Description

callback

Function

Callback

Name

Type

Description

err

Error

rev

String

The current revision

change.equals(change)

Compare two changes.

Arguments

Name

Type

Description

change

Change

change.getModelCtor()

Get the Model class for change.modelName.

change.isBasedOn(change)

Determine if the change is based on the given change.

Arguments

Name

Type

Description

change

Change

change.rectify(callback)

Update (or create) the change with the current revision.

Arguments

Name

Type

Description

callback

Function

Callback

Name

Type

Description

err

Error

change

Change

change.type()

Get a change's type. Returns one of:

Change.UPDATE

Change.CREATE

Change.DELETE

Change.UNKNOWN

Class: Change.Conflict

Change.Conflict

When two changes conflict a conflict is created.

Note: call conflict.fetch() to get the target and source models.

Arguments

Name

Type

Description

modelId

SourceModel

PersistedModel

TargetModel

PersistedModel

Class Properties

Name

Type

Description

source

ModelClass

The source model instance

target

ModelClass

The target model instance

Class: Change.Conflict Instance Methods

conflict.changes(callback)

Get the conflicting changes.

Arguments

Name

Type

Description

callback

Function

Callback

Name

Type

Description

err

Error

sourceChange

Change

targetChange

Change

conflict.models(callback)

Fetch the conflicting models.

Arguments

Name

Type

Description

callback

Function

Callback

Name

Type

Description

err

Error

source

PersistedModel

target

PersistedModel

conflict.resolve(callback)

Resolve the conflict.

Set the source change's previous revision to the current revision of the
(conflicting) target change. Since the changes are no longer conflicting
and appear as if the source change was based on the target, they will be
replicated normally as part of the next replicate() call.

This is effectively resolving the conflict using the source version.

Arguments

Name

Type

Description

callback

Function

Callback

Name

Type

Description

err

Error

conflict.resolveManually(data, callback)

Resolve the conflict using the supplied instance data.

Arguments

Name

Type

Description

data

Object

The set of changes to apply on the model instance. Use null value to delete the source instance instead.

callback

Function

Callback

Name

Type

Description

err

Error

conflict.resolveUsingSource(callback)

Resolve the conflict using the instance data in the source model.

Arguments

Name

Type

Description

callback

Function

Callback

Name

Type

Description

err

Error

conflict.resolveUsingTarget(callback)

Resolve the conflict using the instance data in the target model.

Arguments

Name

Type

Description

callback

Function

Callback

Name

Type

Description

err

Error

conflict.swapParties()

Return a new Conflict instance with swapped Source and Target models.

This is useful when resolving a conflict in one-way
replication, where the source data must not be changed:

Glob string to use to filter returned keys (i.e. userid.*). All connectors are required to support * and
?. They may also support additional special characters that are
specific to the backing database.

options

Object

Returns

Name

Type

Description

result

AsyncIterator

An Object implementing next(cb) -> Promise function that can be used to iterate all keys.

KeyValueModel.keys(filter, cb)

Return all keys in the database.

WARNING: This method is not suitable for large data sets as all
key-values pairs are loaded into memory at once. For large data sets,
use iterateKeys() instead.

Arguments

Name

Type

Description

filter

Object

An optional filter object with the following

filter.match

String

Glob string used to filter returned keys (i.e. userid.*). All connectors are required to support * and
?, but may also support additional special characters specific to the
database.

options

Object

callback

Function

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

WARNING: this promise implementation will not resolve according to
the callback function.

Handler

Argument

Description

resolve

KeyValueModel.set(key, value, cb)

Persist a value and associate it with the given key.

Arguments

Name

Type

Description

key

String

Key to associate with the given value.

value

Any

Value to persist.

options

Number or Object

Optional settings for the key-value pair. If a Number is provided, it is set as the TTL (time to live) in ms
(milliseconds) for the key-value pair.

callback

Function

options

Name

Type

Description

ttl

Number

TTL for the key-value pair in ms.

Callback (optional)

Optional callback. When the callback function is not provided,
a promise is returned instead (see below).

Name

Type

Description

err

Error

Error object.

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

Handler

Argument

Description

resolve

undefined

The resolve handler does not receive any arguments.

KeyValueModel.ttl(key, cb)

Return the TTL (time to live) for a given key. TTL is the remaining time
before a key-value pair is discarded from the database.

Arguments

Name

Type

Description

key

String

Key to use when searching the database.

options

Object

callback

Function

Callback (optional)

Optional callback. When the callback function is not provided,
a promise is returned instead (see below).

Name

Type

Description

error

Error

ttl

Number

Expiration time for the key-value pair. undefined if TTL was not initially set.

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

Handler

Argument

Description

resolve

Number

Expiration time for the key-value pair. undefined if TTL was not initially set.

Class: Role object

Role

The Role model

Class: Role Static Methods

Role.getRoles(context, callback)

List roles for a given principal.

Arguments

Name

Type

Description

context

Object

The security context.

callback

Function

Callback function.

Callback (optional)

Optional callback. When the callback function is not provided,
a promise is returned instead (see below).

Name

Type

Description

err

Error

Error object.

roles

Array.<String>

An array of role IDs

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

Handler

Argument

Description

resolve

Array.<String>

An array of role IDs

Role.isAuthenticated(context, callback)

Check if the user ID is authenticated

Arguments

Name

Type

Description

context

Object

The security context.

callback

Function

Callback function.

Callback (optional)

Optional callback. When the callback function is not provided,
a promise is returned instead (see below).

Name

Type

Description

err

Error

Error object.

isAuthenticated

Boolean

True if the user is authenticated.

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

Handler

Argument

Description

resolve

Boolean

True if the user is authenticated.

Role.isInRole(role, context, callback)

Check if a given principal is in the specified role.

Arguments

Name

Type

Description

role

String

The role name.

context

Object

The context object.

callback

Function

Callback function.

Callback (optional)

Optional callback. When the callback function is not provided,
a promise is returned instead (see below).

Name

Type

Description

err

Error

Error object.

isInRole

Boolean

True if the principal is in the specified role.

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

Class: User Static Methods

Current password, required in order to strongly verify the identity of the requesting user

newPassword

string

The new password to use.

[options]

object

callback

Function

Callback (optional)

Optional callback. When the callback function is not provided,
a promise is returned instead (see below).

Name

Type

Description

err

Error

Error object

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

Handler

Argument

Description

resolve

undefined

The resolve handler does not receive any arguments.

User.confirm(userId, token, redirect, callback)

Confirm the user's identity.

Arguments

Name

Type

Description

userId

Any

token

String

The validation token

redirect

String

URL to redirect the user to once confirmed

callback

Function

Callback (optional)

Optional callback. When the callback function is not provided,
a promise is returned instead (see below).

Name

Type

Description

err

Error

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

Handler

Argument

Description

resolve

undefined

The resolve handler does not receive any arguments.

User.generateVerificationToken(user, options, cb)

A default verification token generator which accepts the user the token is
being generated for and a callback function to indicate completion.
This one uses the crypto library and 64 random bytes (converted to hex)
for the token. When used in combination with the user.verify() method this
function will be called with the user object as it's context (this).

Arguments

Name

Type

Description

user

object

The User this token is being generated for.

options

object

remote context options.

cb

Function

The generator must pass back the new token with this function call.

User.getVerifyOptions()

Returns default verification options to use when calling User.prototype.verify()
from remote method /user/:id/verify.

NOTE: the User.getVerifyOptions() method can also be used to ease the
building of identity verification options.

User.login(credentials, [include], callback)

If the emailVerificationRequired flag is set for the inherited user model
and the email has not yet been verified then the method will return a 401
error that will contain the user's id. This id can be used to call the
api/verify remote method to generate a new email verification token and
send back the related email to the user.

Arguments

Name

Type

Description

credentials

Object

username/password or email/password

[include]

Array.<String> or String

Optionally set it to "user" to include the user info

callback

Function

Callback function

Callback (optional)

Optional callback. When the callback function is not provided,
a promise is returned instead (see below).

Name

Type

Description

err

Error

Error object

token

AccessToken

Access token if login is successful

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

Either the requested ttl, or an object with token properties to set (see below).

[options]

Object

Additional options including remoting context

cb

Function

The callback function

[ttl|data]

Name

Type

Description

[ttl]

Number

The requested ttl

[scopes]

Array.<String>

The access scopes granted to the token.

Callback (optional)

Optional callback. When the callback function is not provided,
a promise is returned instead (see below).

Name

Type

Description

err

String or Error

The error string or object

token

AccessToken

The generated access token object

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

Handler

Argument

Description

resolve

AccessToken

The generated access token object

user.hasPassword(password, callback)

Compare the given password with the users hashed password.

Arguments

Name

Type

Description

password

String

The plain text password

callback

Function

Callback function

Callback (optional)

Optional callback. When the callback function is not provided,
a promise is returned instead (see below).

Name

Type

Description

err

Error

Error object

isMatch

Boolean

Returns true if the given password matches record

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

Handler

Argument

Description

resolve

Boolean

Returns true if the given password matches record

user.setPassword(newPassword, [options], callback)

Set this user's password. The callers of this method
must ensure the client making the request is authorized
to change the password, typically by providing the correct
current password or a password-reset token.

Arguments

Name

Type

Description

newPassword

string

The new password to use.

[options]

Object

Additional options including remoting context

callback

Function

Callback (optional)

Optional callback. When the callback function is not provided,
a promise is returned instead (see below).

Name

Type

Description

err

Error

Error object

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

Handler

Argument

Description

resolve

undefined

The resolve handler does not receive any arguments.

user.verify(verifyOptions, cb)

Verify a user's identity by sending them a confirmation message.
NOTE: Currently only email verification is supported

A function generating the email HTML body from verify() options object and generated attributes like options.verifyHref.
It must accept the verifyOptions object, the method's remoting context options
object and a callback function with (err, html) as parameters.
A default templateFn function is provided, see createVerificationEmailBody()
for implementation details.

redirect

String

Page to which user will be redirected after they verify their email. Defaults to '/'.

verifyHref

String

The link to include in the user's verify message. Defaults to an url analog to:
http://host:port/restApiRoot/userRestPath/confirm?uid=userId&redirect=/`

host

String

The API host. Defaults to app's host or localhost.

protocol

String

The API protocol. Defaults to 'http'.

port

Number

The API port. Defaults to app's port or 3000.

restApiRoot

String

The API root path. Defaults to app's restApiRoot or '/api'

generateVerificationToken

Function

A function to be used to generate the verification token.
It must accept the verifyOptions object, the method's remoting context options
object and a callback function with (err, hexStringBuffer) as parameters.
This function should NOT add the token to the user object, instead simply
execute the callback with the token! User saving and email sending will be
handled in the verify() method.
A default token generation function is provided, see generateVerificationToken()
for implementation details.

Callback (optional)

Optional callback. When the callback function is not provided,
a promise is returned instead (see below).

Name

Type

Description

options

Object

remote context options.

err

Error

Error object.

object

Object

Contains email, token, uid.

Promise

This method supports both callback-based and promise-based invocation.
Call this method with no callback argument to get back a promise instead.

WARNING: this promise implementation will not resolve according to
the callback function.