Skip to main content
Version: Node.js

Number Verify Reference

To perform a number verification you need to the following steps:

  1. Initiate a number verification session: This is done on the user's device by following a URL provided by the service.
  2. Generate a token: This is done by the backend server once the user has initiated the session.
  3. Check the verification status: This is done by calling the service with the token generated in the previous step.

To initiate the process you use the NumberVerifyClient class. This class is accessible through the GlideClient instance. This can be run from the frontend or backend and only requires a client id and not a client secret. With the NumberVerifyClient instance you can call the getAuthUrl method to get the URL to start the verification process.

info

Once the user has followed the URL and initiated the session they will be redirected to your redirect URL with a code query parameter.

This code can the be used to create a NumberVerifyUserClient instance which will automatically exchange the code for an access token and allow you to call the verifyNumber method to check the verification status.

NumberVerifyClient Reference

Methods

1. getAuthUrl

Description: getAuthUrl retrieves the URL for the user to initiate a number verification session.

Syntax:

getAuthUrl(opts: NumberVerifyAuthUrlInput = {}): Promise<string>;

Parameters:

ParameterTypeDescription
optsNumberVerifyAuthUrlInputAn object containing the auth URL options.

NumberVerifyAuthUrlInput Properties:

PropertyTypeDescription
statestringOptional - A state parameter to pass to the redirect URL.
useDevNumberstringOptional - A phone number to use for testing instead of using IP based routing (only works for sandbox numbers)

Returns:

  • string: The URL for the user to initiate a number verification session. This URL should be opened on the user's device.

Example:

import { GlideClient } from "glide-sdk";

async function main() {
const glide = new GlideClient({
// clientId can be omitted if set in environment variable
clientId: "your-client-id",
});

const url = await glide.numberVerify.getAuthUrl();
console.log(`Open this URL on the user's device: ${url}`);
}

main().catch(console.error);

2. forUser

Description: forUser creates a NumberVerifyUserClient instance by providing the code received from the user's device. Optionally, you can provide a phone number to verify and then call the verifyNumber without providing the phone number again.

Syntax:

forUser(params: NumberVerifyClientForParams): Promise<NumberVerifyUserClient>;

Parameters:

ParameterTypeDescription
paramsNumberVerifyClientForParamsAn object containing the for parameters.

NumberVerifyClientForParams Properties:

PropertyTypeDescription
codestringThe code received from the user's device.
phoneNumberstringOptional - The phone number to verify.

Returns:

  • NumberVerifyUserClient: A NumberVerifyUserClient instance.

Example:

import { GlideClient } from "glide-sdk";

async function main() {
const glide = new GlideClient({
// clientId can be omitted if set in environment variable
clientId: "your-client-id",
});

const code = "code-from-user-device";
const numberVerifyUserClient = await glide.numberVerify.forUser({
code,
phoneNumber: "+555123456789"
});
}

main().catch(console.error);

NumberVerifyUserClient Reference

The NumberVerifyUserClient is used to interact with the Number Verify service for a specific phone number.

Methods

1. verifyNumber

Description: verifyNumber verifies that a the user's phone number matches the phone number provided.

Syntax:

verifyNumber(params: NumberVerifyInput, conf: ApiConfig): Promise<NumberVerifyResponse>;

Parameters:

ParameterTypeDescription
paramsNumberVerifyInputAn object containing the verification parameters.
confApiConfigAn object containing optional API configuration like session.

NumberVerifyInput Properties:

PropertyTypeDescription
phoneNumberstringThe phone number to verify. can be omitted if provided in the forUser method.

Returns:

  • NumberVerifyResponse: An object containing the verification status.

NumberVerifyResponse Properties:

PropertyTypeDescription
devicePhoneNumberVerifiedbooleanWhether the phone number is verified.

Example:

import { GlideClient } from "glide-sdk";

async function main() {
const glide = new GlideClient();

const numberVerifyUserClient = await glide.numberVerify.forUser({
code: "code-from-user-device",
phoneNumber: "+555123456789"
});

const numberVerifyResponse = await numberVerifyUserClient.verifyNumber();
if (numberVerifyResponse.devicePhoneNumberVerified) {
console.log("Phone number verified");
} else {
console.log("Phone number not verified");
}
}

main().catch(console.error);

Error Handling

Each method in ExampleService can throw errors under certain conditions. Developers should handle these exceptions as part of their implementation. Common errors include:

  • InvalidInputError: Thrown when input parameters do not meet the required format or type.
  • OperationFailedError: Thrown when an operation cannot be completed successfully due to various issues, such as network problems or service unavailability.

Type Definitions

ApiConfig

This object can be sent to most service apis to override the default configuration like the access token used in the request.

Properties

PropertyTypeDescription
sessionSessionAn optional session object for authentication and authorization.

Session

This object represents a user session with an access token, expiration time, and associated scopes.

Properties

PropertyTypeDescription
accessTokenstringThe access token for the session.
expiresAtnumberThe expiration time of the session.
scopesstring[]An array of scopes associated with the session.