Node.js
Send the verification request
Start the verification process by using the Verify API request endpoint to generate a verification code and send it to the user.
Use the Node Server SDK for this. First, instantiate it after the lines of code that read your environment variables from .env:
const vonage = new Vonage(
{
apiKey: VONAGE_API_KEY,
apiSecret: VONAGE_API_SECRET,
},
{
debug: true,
}
);
Then, create the verification request within the /verify route handler:
app.post('/verify', (req, res) => {
// Start the verification process
verifyRequestNumber = req.body.number;
vonage.verify.request(
{
number: verifyRequestNumber,
brand: VONAGE_BRAND_NAME,
},
(err, result) => {
if (err) {
console.error(err);
} else {
verifyRequestId = result.request_id;
console.log(`request_id: ${verifyRequestId}`);
}
}
);
/*
Redirect to page where the user can
enter the code that they received
*/
res.render('entercode');
});
By default, the first verification attempt is sent by SMS. If the user fails to respond within a specified time period then the API makes a second and, if necessary, third attempt to deliver the PIN code using a voice call. You can learn more about the available workflows and customization options in our guide.
Step-up Authentication
Add an extra layer of security when users perform sensitive tasks
手順
1
Introduction2
Create the Node.js application3
Initialize your dependencies4
Configure the application5
Define the routes6
Create the UI7
Display the home page8
Send the verification request9
Check the verification code10
Try it out!11
What's next?