-
-
Save DanyF-github/05047c9778cc52dc179050f7399d6bbc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// server/src/services/vonage/verify.js | |
... | |
const verifyRequest = (number) => { | |
return new Promise((resolve, reject) => { | |
// get the Vonage client | |
const vonageClient = getVonageClient(); | |
const brand = 'Vonage APIs'; | |
// Create a verification request for the given number | |
vonageClient.verify.request({number, brand}, (err, result) => { | |
if (err) { | |
reject(false); | |
} else { | |
// return the request id which will be used when verifying the code | |
resolve(result.request_id); | |
} | |
}); | |
}); | |
}; | |
const checkCode = (code, request_id) => { | |
return new Promise((resolve, reject) => { | |
// get the Vonage client | |
const vonageClient = getVonageClient(); | |
// here pass both the request id and the code sent by the student | |
vonageClient.verify.check({ | |
request_id, | |
code | |
}, (err, result) => { | |
if (err) { | |
reject(false); | |
} else { | |
// if code is correct we authenticate the student | |
if (result.status === '0') { | |
resolve(true); | |
} else { | |
reject(false); | |
} | |
} | |
}); | |
}) | |
} | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment