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

Not working for me, its showing timeout errror

Open vishnulanka-dataevolve opened this issue 2 years ago • 22 comments

Sometimes its showing timeout and some times its not even working. can anyone share me working example.

vishnulanka-dataevolve avatar Sep 07 '23 10:09 vishnulanka-dataevolve

same issue face

ankitsharma29 avatar Sep 09 '23 16:09 ankitsharma29

useEffect(() => { RNOtpVetify.getHash() .then(console.log) .catch(console.log); RNOtpVetify.getOtp() .then(p => RNOtpVetify.addListener(OTPHandler)) .catch(p => console.log(p));

return () => RNOtpVetify.removeListener();

}, []);

const OTPHandler = (message) => { console.log(message);

// const otps = getNumberFromString('number', message?.body);
// if (otps && otps.length > 0 && otps[0].length === otpLength) {
//   console.log("message", message, otps);
// }
const otp = /(\d{6})/g.exec(message);
console.log("message otp", otp);
  // onFillOTPData(otp);
RNOtpVetify.removeListener();

} timeout errror

ankitsharma29 avatar Sep 09 '23 16:09 ankitsharma29

i am also facing the same error here is my code snippet

async otpRead() {
    console.log('otpRead--> ');
    getHash()
      .then(hash => {
        console.log('hash--->', 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
      console.log('message-->', message);
      const otp = /(\d{4})/g.exec(message)[1];
      console.log('otp--->', otp);
    });
  }

Azeem00786 avatar Nov 29 '23 06:11 Azeem00786

Any solution?

mariaalm20 avatar Dec 07 '23 14:12 mariaalm20

same issue :((((

MinhThu100200 avatar Dec 21 '23 14:12 MinhThu100200

Hello, we're still encountering this issue. Could someone please assist us?

ankitch29 avatar Jan 24 '24 10:01 ankitch29

same issue, any solutions?

elencho avatar Feb 15 '24 12:02 elencho

Please try in latest version and use hook if possible

faizalshap avatar Apr 09 '24 07:04 faizalshap

is this fix still facing same issue in latest version?

Suman028 avatar Sep 20 '24 07:09 Suman028

same issue, any solutions please?

mainu007 avatar Oct 17 '24 05:10 mainu007

same issue , any progress?

tayyabrajpoot12 avatar Nov 08 '24 09:11 tayyabrajpoot12

Hello Community,

Unfortunately, it doesn't work for me either, and I'm using RN 0.74.5. Sometimes it shows time out error, others it doesn't, but simply doesn't work.

palmtown avatar Nov 15 '24 07:11 palmtown

what is the otp message you get? does it have a hash code?

Suman028 avatar Nov 15 '24 08:11 Suman028

what is the otp message you get? does it have a hash code?

Hello @Suman028

Please note that no otp message is received at all. getHash does receive an event, but nothing from otp.

palmtown avatar Nov 15 '24 16:11 palmtown

in the otp message you get, there should be hash code right?

Suman028 avatar Nov 15 '24 16:11 Suman028

in the otp message you get, there should be hash code right?

Hello @Suman028

Please note that startOtpListener never receives a message when an sms is received. The only event that is received is in getHash.then(...). This Meaning, the otp is never received.

palmtown avatar Nov 15 '24 16:11 palmtown

i asking in the message there should be hash code, if the hash code is not present the otp message would not be received

Suman028 avatar Nov 15 '24 16:11 Suman028

i asking in the message there should be hash code, if the hash code is not present the otp message would not be received

Hello @Suman028

I believe I now understand your response clearly. I will apply it and respond with full details so other users can fix the issue as well very shortly.

palmtown avatar Nov 15 '24 16:11 palmtown

hey here are the steps to get the hash string, if required - link

Suman028 avatar Nov 15 '24 16:11 Suman028

hey here are the steps to get the hash string, if required - link

Hello @Suman028,

You are absolutely correct. The issue, at least for me, was simply overlooking the snippet in the instructions that states:

"In order to detect the message, the SMS message must include a hash that identifies your app. This hash can be obtained by using the getHash() method below."

This means that when you receive a text message, it must include the hash returned by getHash(); otherwise, the detection will not work.

For others who may encounter the same issue, please ensure that your SMS message includes the hash returned from getHash(). Additionally, one detail that wasn’t immediately clear is that you need to prepend the hash code with a # symbol for it to function correctly.

With that said, thank you for your insightful comments—they helped me resolve the issue! If you have a Buy Me a Coffee or Cash App link, feel free to share it, and I’d be happy to send you a coffee as a token of appreciation.

Ultimately, my problem boiled down to not thoroughly reading the instructions.

Exhibit 1: image

palmtown avatar Nov 15 '24 17:11 palmtown

@palmtown I also R & D on this for 2-3 days and finally noticed the issue, happy that it worked

Suman028 avatar Nov 15 '24 17:11 Suman028

Hello @Suman028 and community,

I submitted a PR at https://github.com/faizalshap/react-native-otp-verify/pull/128 which aims to ensure absolute clarity regarding the SMS message format required for the OTP functionality. Specifically:

  1. Emphasizes that the SMS message must include the hash generated by the getHash() method.

  2. Explicitly states that the hash must be prepended with a # symbol for the functionality to work correctly.

  3. Adds examples and restructured the relevant section to make this requirement stand out, reducing the likelihood of it being overlooked by developers.

palmtown avatar Nov 15 '24 19:11 palmtown