Installations
npm install react-native-otp-verify
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
16.18.1
NPM Version
8.19.2
Releases
Contributors
Unable to fetch Contributors
Languages
Java (64.35%)
TypeScript (17.05%)
Objective-C (9.89%)
JavaScript (4.53%)
Ruby (3.67%)
C (0.32%)
Swift (0.19%)
Developer
faizalshap
Download Statistics
Total Downloads
1,953,787
Last Day
3,210
Last Week
14,524
Last Month
64,575
Last Year
731,053
GitHub Statistics
261 Stars
57 Commits
99 Forks
6 Watching
3 Branches
18 Contributors
Bundle Size
2.24 kB
Minified
969.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.1.8
Package Id
react-native-otp-verify@1.1.8
Unpacked Size
392.54 kB
Size
122.84 kB
File Count
102
NPM Version
8.19.2
Node Version
16.18.1
Publised On
16 Feb 2024
Total Downloads
Cumulative downloads
Total Downloads
1,953,787
Last day
-14.9%
3,210
Compared to previous day
Last week
-13.8%
14,524
Compared to previous week
Last month
15.9%
64,575
Compared to previous month
Last year
41.1%
731,053
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
2
Dev Dependencies
19
React Native Otp Verify ✉️
- Automatic SMS Verification with the SMS Retriever API (Android Only)
- Phone Number Retrieving using the Phone Number Hint API (Android Only)
Automatic SMS Verification with the SMS Retriever API, you can perform SMS-based user verification in your Android app automatically, without requiring the user to manually type verification codes, and without requiring any extra app permissions.
Message Format/Structure
In order to detect the message, SMS message must include a hash that identifies your app. This hash can be obtained by using the getHash() method below.
Please read the official documentation for the message structure at this Google developer guide
Quick start 🔥
Installation
$ npm install react-native-otp-verify --save
or
$ yarn add react-native-otp-verify
Usage
Import the Library
1import { 2 getHash, 3 startOtpListener, 4 useOtpVerify, 5} from 'react-native-otp-verify';
Using Hook
1 2// You can use the startListener and stopListener to manually trigger listeners again. 3// optionally pass numberOfDigits if you want to extract otp 4const { hash, otp, message, timeoutError, stopListener, startListener } = useOtpVerify({numberOfDigits: 4});
Properties
Property | Type | Description |
---|---|---|
hash | string[] | The hash code for the application which should be added at the end of message. |
otp | string | OTP retreived from SMS when received. (Must pass numberOfDigits ) |
message | string | SMS message when received. |
timeoutError | boolean | Flag is set to true when after timeout (5 minutes) Check here |
startListener | function | Manually starts listener again in case of timeout or any other error |
stopListener | function | Stops listener for the sms |
Using Methods
1// using methods 2useEffect(() => { 3 getHash().then(hash => { 4 // use this hash in the message. 5 }).catch(console.log); 6 7 startOtpListener(message => { 8 // extract the otp using regex e.g. the below regex extracts 4 digit otp from message 9 const otp = /(\d{4})/g.exec(message)[1]; 10 setOtp(otp); 11 }); 12 return () => removeListener(); 13}, []);
Example
See the example app in example
folder.
Auto Linking for React Native >= 0.60
Linking the package manually is not required anymore with Autolinking.
Manual Linking
- Open up
android/app/src/main/java/[...]/MainActivity.java
- Add
import com.faizal.OtpVerify.OtpVerifyPackage;
to the imports at the top of the file - Add
new OtpVerifyPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:1include ':react-native-otp-verify' 2project(':react-native-otp-verify').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-otp-verify/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:1 implementation project(':react-native-otp-verify')
Methods
requestHint: () => Promise<string>
Gets phone number in a frictionless way to show a user’s (SIM-based) phone numbers as a hint. Check here
startOtpListener(handler:(message:string)=>any):Promise<Subscription>
Start listening for OTP/SMS and adds listener for the handler passed which is called when message is received..
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.
addListener(handler:(message:string)=>any):Subscription
Adds a javascript listener to the handler passed which is called when message is received.
removeListener():void
Removes all listeners.
No vulnerabilities found.
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
binaries present in source code
Details
- Warn: binary detected: android/gradle/wrapper/gradle-wrapper.jar:1
- Warn: binary detected: example/android/gradle/wrapper/gradle-wrapper.jar:1
Reason
Found 8/23 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 15 are checked with a SAST tool
Reason
24 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-f5x2-xv93-4p23
- Warn: Project is vulnerable to: GHSA-gmpm-xp43-f7g6
- Warn: Project is vulnerable to: GHSA-pf27-929j-9pmm
- Warn: Project is vulnerable to: GHSA-327c-qx3v-h673
- Warn: Project is vulnerable to: GHSA-x4cf-6jr3-3qvp
- Warn: Project is vulnerable to: GHSA-mph8-6787-r8hw
- Warn: Project is vulnerable to: GHSA-7mhc-prgv-r3q4
- Warn: Project is vulnerable to: GHSA-78xj-cgh5-2h22
- Warn: Project is vulnerable to: GHSA-2p57-rm9w-gvfp
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-rxrc-rgv4-jpvx
- Warn: Project is vulnerable to: GHSA-7f53-fmmv-mfjv
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
- Warn: Project is vulnerable to: GHSA-fhg7-m89q-25r3
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
2.1
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to react-native-otp-verify
react-native-otp-entry
A fully modifiable OTP Input Component for React Native
react-native-verify-otp-inputs
react-native-verify-otp is a tiny Javascript library which provides an elegant UI for the end user to input OTP
react-native-otp-verify-remastered
Verify SMS messages natively through React-Native without requiring additional permissions.
react-native-onetapinput
React Native OneTapInput is a customizable, easy-to-use, and highly customizable OTP input component for React Native.