Avishkar Patil
Avishkar Patil

Reputation: 228

How to auto verify OTP in React Native on android?

I am trying to auto verify otp using react-native-sms-retriever on android devices. I have tried following way to achieve.

 import SmsRetriever from 'react-native-sms-retriever';

 // Get the phone number (first gif)
 _onPhoneNumberPressed = async () => {
 try {
 const phoneNumber = await SmsRetriever.requestPhoneNumber();
 } catch (error) {
 console.log(JSON.stringify(error));
 }
 };

 // Get the SMS message (second gif)
 _onSmsListenerPressed = async () => {
 try {
 const registered = await SmsRetriever.startSmsRetriever();
 if (registered) {
 SmsRetriever.addSmsListener(event => {
 console.log(event.message);
 SmsRetriever.removeSmsListener();
 }); 
 }
 } catch (error) {
 console.log(JSON.stringify(error));
 }
 };

Following is my OTP format

OTP for your login to Orgpick is 3242. Please enter OTP  within 10 minutes.

Also I have created sms format as follows dummy key-SZ3KPh5voKE Please guide me with following sms format.

Shall I need to get same format from server end?

What changes need to be done at server side?

<#>OTP for your login to Orgpick is 3242. Please enter OTP  within 10 minutes.SZ3KPh5voKE

While trying above solution it showing time out exception

Please help me to get out from it.

Upvotes: 1

Views: 8403

Answers (3)

suranga upul
suranga upul

Reputation: 259

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

Upvotes: 0

Sagar H
Sagar H

Reputation: 5541

I have tried two libraries for auto otp verification but none of them worked for me then I have tried with following library its working fine.Please check answer i have uploaded here

Auto otp verification

Upvotes: 1

Rishav Kumar
Rishav Kumar

Reputation: 5460

That is basically a key issue. The Hex code key which you are sending in the message may not be correct which is causing this issue. Try generating a perfect key and send it to the message.

Note production key and debug key are different. Your's look like debug key.

https://github.com/Bruno-Furtado/react-native-sms-retriever/issues/4

This issue answer will help you.

Upvotes: 0

Related Questions