From 953dd3c954411d92811415cc9be4a7c7d76ab185 Mon Sep 17 00:00:00 2001 From: rohan09-raj Date: Fri, 19 Aug 2022 00:10:29 +0530 Subject: added otp support --- server/controllers/otp.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 server/controllers/otp.js (limited to 'server/controllers/otp.js') diff --git a/server/controllers/otp.js b/server/controllers/otp.js new file mode 100644 index 0000000..5b4bd82 --- /dev/null +++ b/server/controllers/otp.js @@ -0,0 +1,17 @@ +import generateOTP from '../utils/otp'; +import sendMessage from '../services/twilio'; + +const sendOTP = async (req, res) => { + const {mobile} = req.body; + + try { + const otp = generateOTP(); + const message = `Your OTP for Aadhaar verification is : ${otp}`; + sendMessage(mobile, message); + res.status(200).json({message: 'OTP sent successfully', otpCode: otp}); + } catch (error) { + res.status(404).json({message: error}); + } +}; + +export default {sendOTP}; -- cgit