react-native-otp-verify icon indicating copy to clipboard operation
react-native-otp-verify copied to clipboard

Not detecting OTP automatically

Open mehdihussain9 opened this issue 5 years ago • 13 comments

can you provide any full-example with <TextInput> and etc.. I'm confused to where to place that code in my js file

mehdihussain9 avatar Nov 13 '19 18:11 mehdihussain9

I have 11 charcter hash code but same issue for me. Not detecting the otp automatically.

UPDATE On OTP Component I managed to work this Auto detect OTP. when calling this.getHash(); in componentDidMount you will get the 11 character hash code which will then be used to add in our SMS body eg .

[#] Your AndroidApp code is: 589645 
e56cQRXERi/  //this is the 11 character hash code
   componentDidMount(){
        this.getHash();
        this.startListeningForOtp();
    }
    componentWillUnmount() {
        RNOtpVerify.removeListener();
     }

    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) => {
            console.log(message);
            const otp = /(\d{6})/g.exec(message)[1];
            console.log(otp);
            this.setState({ otp });
            RNOtpVerify.removeListener();
            // Keyboard.dismiss();
    }

abhiburk avatar Nov 14 '19 11:11 abhiburk

same issue for me got confused with .ts file. can you please provide example in .js file?

Charmismehta avatar Dec 24 '19 09:12 Charmismehta

ok cool

faizalshap avatar Feb 13 '20 10:02 faizalshap

same

Tohid1999 avatar Mar 17 '20 08:03 Tohid1999

Hi guys, I used this package for auto verification of OTP. It works great, but at times its not detecting OTP. Do anyone have any idea of what's causing the problem? I'm stuck at this place for past few days. Any help would be great!

Arun-paramasivam avatar Jul 07 '20 09:07 Arun-paramasivam

Actually problem is different hashcode for debug and release. when you will compare hashcode of debug and release it will be different

sumit-android-haridwar avatar Jul 21 '20 04:07 sumit-android-haridwar

Please check your play service is up to date. I had the same problem and fixed it by updating the play service.

Surangaup avatar May 14 '21 06:05 Surangaup

same issue, have any solution?

rakeshpangil avatar May 27 '21 06:05 rakeshpangil

You will get 11 characters hash code that you have to use in your text message.

the text message would be like: Your 6-digit code: 329769 is valid for 10 minutes 1kTcOHIoaXD

Note: in the text message, the hash code must be in the next line.

The below code is working fine for me.

useEffect(() => {
    this.getHash();
    this.startListeningForOtp();
  },[])

  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{6})/g.exec(message)[1];
    setMatchingOtp(otp);
    RNOtpVerify.removeListener();
    Keyboard.dismiss();
  }

hpsurekha avatar Sep 16 '21 14:09 hpsurekha

Is there a way to use this without putting the hash code in the text message?

Rache-lBronfman avatar Jan 26 '22 10:01 Rache-lBronfman

@aakashtyagiwmp can you share here a snippet of how you implemented it? or a repo probably so people here could help.

jovanialferez avatar Mar 11 '22 08:03 jovanialferez

I have weird issue. Otp detect work on builds (apk) but fails on bundles (aab)

@faizalshap

viv3kk avatar Jul 29 '22 07:07 viv3kk

I have weird issue. Otp detect work on builds (apk) but fails on bundles (aab)

@faizalshap

Have you found a solution for the problem?

AndreiBehel avatar Aug 17 '22 08:08 AndreiBehel

.aab created a different hash key in my case.

shailesh-galgal avatar Oct 25 '22 11:10 shailesh-galgal

I have weird issue. Otp detect work on builds (apk) but fails on bundles (aab)

@faizalshap

.aab created a different hash key in my case.

shailesh-galgal avatar Oct 25 '22 11:10 shailesh-galgal

@viv3kk make sure that the Hash is correct @mehdihussain9 the example is added Thanks 👍

faizalshap avatar Oct 30 '22 08:10 faizalshap