API Docs for: 1.4.7
Show:

Verification Class

Provides Verification over SMS.

Note: Do not instantiate Verification, rather use the createSmsVerification() method in SinchClient. See the example below.

Constructor

Verification

(
  • sinch
  • number
  • [custom]
)

Parameters:

  • sinch SinchClient

    The parent object

  • number String

    The phone number to verify

  • [custom] String optional

    Custom string to pass to your backend through callback. Useful for identifying user session, or similar. Max size is 4 kbyte.

Example:

// Get verificationClient from sinchClient
var sinchClient = new SinchClient(...);
var verification = sinchClient.createSmsVerification('+46123456789'); // Verification to telephone +46123456789

// Send a verification code 
verification.initiate();

// Verify CODE, will trigger callback configured in partner portal
verification.verify(CODE).then(function() {
    // Take action on successful verification
}); 

Item Index

Methods

initiate

(
  • success
  • fail
)
chainable

Initiate verification by requesting an SMS with secret code to be sent to the phone number provided earlier. Returns promise which is resolved when initiated.

Note: This method can be called multiple times, in case user requests re-sending the SMS.

Parameters:

  • success Function

    Optional success callback, method also returns a promise for chaining

  • fail Function

    Optional fail callback, method also returns a promise for chaining

Returns:

promise Promise which resolves when verified, fail resolves with VerificationError

Example:

//Get verificationClient from sinchClient
var sinchClient = new SinchClient(...);
var verification = sinchClient.createSmsVerification(+46123456789); // Verification to telephone +46123456789

//Send a verification code 
verification.initiate().then(function() {
    //Ask user to enter secret CODE
}).fail(function(error) {
    //Infom user of error sending SMS (more info in error.message)
});

request

(
  • success
  • fail
)
protected chainable

Request a verification - Internal method, do not use

Parameters:

  • success Function

    Optional success callback

  • fail Function

    Optional fail callback

Returns:

promise - Promise which resulves when request is successful, fail resolves with VerificationError

retry

(
  • success
  • fail
)
chainable

Retry verification by re-sending a new verification SMS. Returns promise which is resolved when verified.

Parameters:

  • success Function

    Optional success callback

  • fail Function

    Optional fail callback

Returns:

promise Promise which resolves when verified, fail resolves with VerificationError

Example:

//Get verificationClient from sinchClient
var sinchClient = new SinchClient(...);
var verification = sinchClient.createSmsVerification(+46123456789); // Verification to telephone +46123456789

//Send a verification code 
verification.initiate().then(function() {
    //Ask user to enter secret CODE
}).fail(function(error) {
    //Infom user of error sending SMS (more info in error.message)
});

//Re-send a verification code 
verification.retry().then(function() {
    //Ask user to enter secret CODE
}).fail(function(error) {
    //Infom user of error sending SMS (more info in error.message)
}); 

verify

(
  • code
  • success
  • fail
)
chainable

Verify a code retrieved over a secondary channel. Pass in code, success and fail callbacks, or rely on promises.

Note: The code for a particular verification session can only attempt verification at most five times.

Parameters:

  • code String

    Mandatory code to verify, this code should have been retrieved from the user (who got it through SMS)

  • success Function

    Optional success callback, method also returns a promise for chaining

  • fail Function

    Optional fail callback, method also returns a promise for chaining

Returns:

promise Promise which resolves when verified, fail resolves with VerificationError

Example:

//Get verificationClient from sinchClient
var sinchClient = new SinchClient(...);
var verification = sinchClient.createSmsVerification(+46123456789); // Verification to telephone +46123456789

//Send a verification code 
verification.initiate().then(function() {
    //Ask user to enter secret CODE
}).fail(function(error) {
    //Infom user of error sending SMS (more info in error.message)
});

//Verification of code
verification.verify(CODE).then(function() {
    //Perform action on successful verification
}).fail(function(error) {
    //Perform action on unsuccessful verification
});