faizalshap / react-native-otp-verify

React native sms verification without additional permissions
MIT License
243 stars 95 forks source link

Not detecting OTP automatically #11

Closed mehdihussain9 closed 1 year ago

mehdihussain9 commented 4 years ago

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

abhiburk commented 4 years ago

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();
    }
Charmismehta commented 4 years ago

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

faizalshap commented 4 years ago

ok cool

Tohid1999 commented 4 years ago

same

Arun-paramasivam commented 4 years ago

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!

sumit-android-haridwar commented 4 years ago

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

Surangaup commented 3 years ago

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

rakeshpangil commented 3 years ago

same issue, have any solution?

hpsurekha commented 3 years ago

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();
  }
Rache-lBronfman commented 2 years ago

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

jovanialferez commented 2 years ago

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

viv3kk commented 2 years ago

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

@faizalshap

AndreiBehel commented 2 years ago

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

@faizalshap

Have you found a solution for the problem?

shailesh-galgal commented 1 year ago

.aab created a different hash key in my case.

shailesh-galgal commented 1 year ago

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.

faizalshap commented 1 year ago

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