JVerify JavaScript Library
If you haven't already familiarized yourself with the general docs, we recommend doing that before beginning a project.
JVerify offers both an HTTP endpoint as well as libraries for your language of choice. This documents the usage of our JavaScript library.
Prerequisites
You need to have the JVerify library installed as well as node.js requests.
npm i jverify-js requests
Importing & intializing
In your node.js file, enter the following code:
const JVerify_lib = require('./javascript.js');
const JVerify = new JVerify_lib({
token:'T3h5N3RyUPNT4NkQ73cuUtdh_cpNsXHG...',
vendor:'JVerify'
});
Now the JVerify library is set up to send messages!
Notice how the constructor takes an object, with schema:
{
token:'your-token',
vendor:'your-company-name'
}
The Start Method
Sample implementation:
let hash;
JVerify.start({
name:'John Smith',
number:2025550106
}).then(r => {
if(r.code == 200 || r.code == 203) {
hash = r.body.hash;
} else {
throw new Error(`JVerify threw error ${r.code} (${r.status}): ${r.message}`);
}
})
Just like the constructor, the .start
method takes an object with schema:
{
name:'users-name',
number:'users-phone-number'
}
The start method returns a promise
which will evaluate in the then
block in the sample code. The promise will return an object with schema:
{
code:200,
message:'what the above code means (from the JVerify documentation)',
status:'what the above code officially means (official name)',
body:{
success:true,
hash:'hash-of-sent-pin'
}
}
Data types:
{
code:int,
message:string,
status:string,
body:object:{
success:boolean,
hash:string
}
}
You should save body.hash
to use in the verify request. The hash is non-sensitive, meaning it is safe to be sent to your front end or saved in user's cookies.
The Verify Method
Sample implementation:
JVerify.verify({
hash:'hash-from-start-method',
pin:393545
}).then(r => {
if(r.code > 199 && r.code < 300) {
console.log('PIN Correct!')
} else {
console.log('PIN Incorect')
}
} else {
throw new Error(`JVerify threw error ${r.code} (${r.status}): ${r.message}`);
}
})
Just like the constructor and start method, the .verify
endpoint takes an object with schema:
{
hash:'hash-from-start-method',
pin:'pin from frontend'
}
Just like the .start
method, the .verify
method returns a promise
which will evaluate in the then
block in the sample code. The promise will return an object with schema:
{
code:200
message:'what the above code means (from the JVerify documentation)'
status:'what the above code officially means (official name)'
body:{
correct:true
}
}
With data types:
{
code:int,
message:string,
status:string,
body:object:{
correct:boolean
}
}