react-native-otp-verify vs react-native-otp-textinput
React Native OTP Libraries Comparison
1 Year
react-native-otp-verifyreact-native-otp-textinput
What's React Native OTP Libraries?

These libraries facilitate the implementation of One-Time Password (OTP) functionalities in React Native applications. They help developers create user-friendly interfaces for OTP input and verification, enhancing security for user authentication processes. By leveraging these libraries, developers can streamline the process of sending and verifying OTPs, which is crucial for applications requiring secure user logins or transactions.

Package Weekly Downloads Trend
Github Stars Ranking
Stat Detail
Package
Downloads
Stars
Size
Issues
Publish
License
react-native-otp-verify18,233263402 kB27a year agoMIT
react-native-otp-textinput11,25916030.5 kB289 months agoMIT
Feature Comparison: react-native-otp-verify vs react-native-otp-textinput

User Interface

  • react-native-otp-verify:

    While this package does not focus on UI components, it integrates well with existing UI frameworks, allowing developers to implement OTP verification logic without worrying about the input interface. It is designed to work alongside other UI components to provide a complete solution.

  • react-native-otp-textinput:

    This package offers a highly customizable OTP input field that allows developers to style the input boxes according to their application's design language. It supports features like auto-focusing on the next input field, which enhances the user experience by making the OTP entry process seamless and intuitive.

Verification Process

  • react-native-otp-verify:

    This package is specifically designed for the verification of OTPs. It provides methods to validate the OTP entered by the user against the one sent via SMS or other channels, making it a crucial component for applications that require secure user authentication.

  • react-native-otp-textinput:

    This library primarily focuses on the input aspect of OTP entry, allowing developers to capture user input efficiently. It does not handle the verification process itself, which means developers need to implement the logic to send and verify the OTP separately.

Integration

  • react-native-otp-verify:

    This package is built to work seamlessly with backend services, making it easy to connect with APIs for sending and verifying OTPs. It is particularly useful when paired with services like Firebase or custom backend solutions.

  • react-native-otp-textinput:

    Easily integrates with various state management libraries and can be used alongside other React Native components. It is lightweight and does not impose heavy dependencies, allowing for flexible integration into existing projects.

Customization

  • react-native-otp-verify:

    Focuses less on customization and more on functionality. It provides a straightforward API for OTP verification, which may limit visual customization but ensures a robust verification process.

  • react-native-otp-textinput:

    Offers extensive customization options for input fields, including the ability to change colors, sizes, and styles. Developers can create a unique look and feel that matches their application's branding, enhancing user engagement.

Learning Curve

  • react-native-otp-verify:

    While the verification logic may require a deeper understanding of backend integration, the library itself is easy to use. Developers may need to familiarize themselves with the OTP verification process, but the API is designed to be intuitive.

  • react-native-otp-textinput:

    This library is relatively easy to learn and implement, especially for developers familiar with React Native. Its clear documentation and straightforward API make it accessible for quick integration into projects.

How to Choose: react-native-otp-verify vs react-native-otp-textinput
  • react-native-otp-verify:

    Opt for 'react-native-otp-verify' if your focus is on the backend verification of OTPs sent via SMS or other channels. This package simplifies the process of verifying OTPs, providing a more comprehensive solution for handling OTP verification logic, especially when integrated with backend services.

  • react-native-otp-textinput:

    Choose 'react-native-otp-textinput' if you need a customizable and visually appealing input component specifically designed for entering OTPs. It provides a straightforward way to create a user interface for OTP input with features like auto-focus and styling options, making it ideal for applications that prioritize user experience.

README for react-native-otp-verify

React Native Otp Verify ✉️


npm version

  • 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

import {
  getHash,
  startOtpListener,
  useOtpVerify,
} from 'react-native-otp-verify';

Using Hook


// You can use the startListener and stopListener to manually trigger listeners again.
// optionally pass numberOfDigits if you want to extract otp
const { 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

// using methods
useEffect(() => {
  getHash().then(hash => {
    // use this hash in the message.
  }).catch(console.log);

  startOtpListener(message => {
    // extract the otp using regex e.g. the below regex extracts 4 digit otp from message
    const otp = /(\d{4})/g.exec(message)[1];
    setOtp(otp);
  });
  return () => removeListener();
}, []);

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

  1. 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 the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-otp-verify'
    project(':react-native-otp-verify').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-otp-verify/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      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.