Original Package react-native-otp-verify
Currently supported React Native version: >= 0.64.0
The SMS Retriever API is used in Automatic SMS Verification. You can use the API to automatically verify users’ identities through SMS, without requiring them to type verification codes manually or requiring them to grant additional permissions to your app.
## Message Format/Structure In order to detect the message, a hash that identifies your application must be included in the SMS. Below, you can find this hash by using the getHash() method.
For more information on the message structure, consult the official documentation here. Google developer guide
npm i react-native-otp-verify-remastered
or
yarn add react-native-otp-verify-remastered
import RNOtpVerify from 'react-native-otp-verify-remastered';
// THIS PACKAGE ONLY FOR ANDROID
getHash = () =>
RNOtpVerify.getHash()
.then(console.log)
.catch(console.log);
startListeningForOtp = () =>
RNOtpVerify.getOtp()
.then(p => RNOtpVerify.addListener(this.otpHandler))
.catch(p => console.log(p));
otpHandler = (message: string) => {
const otp = /(\d{4})/g.exec(message)[1];
this.setState({ otp });
RNOtpVerify.removeListener();
Keyboard.dismiss();
}
getMobilehint = () => {
RNOtpVerify.requestHint()
.then((h) => console.log(h))
.catch((e) => console.log(e));
}
componentWillUnmount() {
RNOtpVerify.removeListener();
}
This project includes an example React Native app. You can run the apps by following these steps:
cd ~
git clone git@github.com:pushpender-singh-ap/react-native-otp-verify-remastered.git
example
cd react-native-otp-verify-remastered/example
npm install
react-native run-android
getOtp():Promise<boolean>
Start listening for OTP/SMS. Return true if listener starts else throws error.
getOtp():Promise<boolean>
Start listening for OTP/SMS. Return true if listener starts else throws error.
getHash():Promise<string[]>
Gets the hash code for the application which should be added at the end of message. This is just a one time process.
requestHint():Promise<string[]>
This method is part of sms retreiver api and its show available phone number list.
addListener(handler:(message:string)=>any):Promise<boolean>
Adds a javascript listener to the handler passed which is called when message is received.
removeListener():void
Removes the listener.