Number Verify Reference
To perform a number verification you need to the following steps:
- Initiate a number verification session: This is done on the user's device by following a URL provided by the service.
- Generate a token: This is done by the backend server once the user has initiated the session.
- 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.
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:
Parameter | Type | Description |
---|---|---|
opts | NumberVerifyAuthUrlInput | An object containing the auth URL options. |
NumberVerifyAuthUrlInput Properties:
Property | Type | Description |
---|---|---|
state | string | Optional - A state parameter to pass to the redirect URL. |
useDevNumber | string | Optional - 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:
Parameter | Type | Description |
---|---|---|
params | NumberVerifyClientForParams | An object containing the for parameters. |
NumberVerifyClientForParams Properties:
Property | Type | Description |
---|---|---|
code | string | The code received from the user's device. |
phoneNumber | string | Optional - The phone number to verify. |
Returns:
NumberVerifyUserClient
: ANumberVerifyUserClient
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:
Parameter | Type | Description |
---|---|---|
params | NumberVerifyInput | An object containing the verification parameters. |
conf | ApiConfig | An object containing optional API configuration like session. |
NumberVerifyInput Properties:
Property | Type | Description |
---|---|---|
phoneNumber | string | The phone number to verify. can be omitted if provided in the forUser method. |
Returns:
NumberVerifyResponse
: An object containing the verification status.
NumberVerifyResponse Properties:
Property | Type | Description |
---|---|---|
devicePhoneNumberVerified | boolean | Whether 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
Property | Type | Description |
---|---|---|
session | Session | An optional session object for authentication and authorization. |
Session
This object represents a user session with an access token, expiration time, and associated scopes.
Properties
Property | Type | Description |
---|---|---|
accessToken | string | The access token for the session. |
expiresAt | number | The expiration time of the session. |
scopes | string[] | An array of scopes associated with the session. |