Git Product home page Git Product logo

react-native-otp-verify's Introduction

react-native-otp-verify

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

Getting started

$ npm install react-native-otp-verify --save or $ yarn add react-native-otp-verify

Auto Linking

$ react-native link react-native-otp-verify

Manual Linking

  1. Open up android/app/src/main/java/[...]/MainActivity.java
  • Add import com.faizal.OtpVerify.RNOtpVerifyPackage; to the imports at the top of the file
  • Add new RNOtpVerifyPackage() 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:
      compile project(':react-native-otp-verify')

Usage

import RNOtpVerify from 'react-native-otp-verify';

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) => {
    const otp = /(\d{4})/g.exec(message)[1];
    this.setState({ otp });
}

componentWillUnmount() {
    RNOtpVerify.removeListener();
}

Methods


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):Promise<boolean>

Adds a javascript listener to the handler passed which is called when message is received.


removeListener():void

Removes the listener.


react-native-otp-verify's People

Contributors

chakrihacker avatar faizalshap avatar keremcubuk avatar khrizt avatar ovarunendra avatar prawee avatar pushpender-singh-ap avatar raunak-agrawal avatar saeedzhiany avatar thakurballary avatar ulion avatar visheshverma748 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.