UNPKG

@msg91comm/react-native-sendotp

Version:

The SendOtp Verification SDK makes verifying phone numbers easy. SDK supports the verification of phone numbers via SMS & Calls.

67 lines (64 loc) 2.02 kB
export const verificationScript = (widgetId: string, authToken: string) => ` <html> <head> </head> <body onload="initOTPWidget()"> <script type="text/javascript"> var configuration = { widgetId: ":widgetId", tokenAuth: ":authToken", success: (data) => { sendDataToReactNativeApp(data); }, failure: (error) => { sendDataToReactNativeApp(error); } }; </script> <script type="text/javascript" src="https://control.msg91.com/app/assets/otp-provider/otp-provider.js"> </script> <script> function initOTPWidget() { initSendOTP(configuration); } function sendDataToReactNativeApp(data) { window.ReactNativeWebView.postMessage(JSON.stringify(data)); }; </script> </body> </html>`.replace(':widgetId',widgetId).replace(':authToken',authToken) export const exposeVerificationScript = (widgetId: string, authToken: string) => ` <html> <head> </head> <body onload="initOTPWidget()"> <script type="text/javascript"> var configuration = { widgetId: ":widgetId", tokenAuth: ":authToken", exposeMethods: true, success: (data) => { // sendDataToReactNativeApp(data); }, failure: (error) => { // sendDataToReactNativeApp(error); } }; </script> <script type="text/javascript" src="https://control.msg91.com/app/assets/otp-provider/otp-provider.js"> </script> <script> function initOTPWidget() { setTimeout(initSendOTP(configuration), 500); } function sendDataToReactNativeApp(data) { window.ReactNativeWebView.postMessage(JSON.stringify(data)); }; const widgetDataInterval = setInterval(() => { let widgetData = window.getWidgetData(); if (widgetData) { window.ReactNativeWebView.postMessage(JSON.stringify(widgetData)); clearInterval(widgetDataInterval); } }, 1000); </script> </body> </html>`.replace(':widgetId',widgetId).replace(':authToken',authToken)