Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to fetch OTP in some devices #69

Open
shailesh-galgal opened this issue Nov 10, 2022 · 13 comments
Open

Fails to fetch OTP in some devices #69

shailesh-galgal opened this issue Nov 10, 2022 · 13 comments

Comments

@shailesh-galgal
Copy link

i.e
Auto-fill not working for the first time but working on the second try, able to re-produce this issue every time on the first attempt.
Device: Samsung M12
Device - Nord
Some times its not even fetching OTP in 2nd attempt as well. @faizalshap need help

@faizalshap
Copy link
Owner

Hi @shailesh-galgal Please share code snippet and library version that you are using

@shailesh-galgal
Copy link
Author

shailesh-galgal commented Nov 10, 2022

created a hook-

export function useOtpAutofetchHandler() {
  const [autoFetchedOTP, setAutofetchedOTP] = useState('')

  const getHash = () => {
    if (Platform.OS === 'android') {
      RNOtpVerify.getHash().then(undefined).catch(undefined)
    }
  }

  const startListeningForOtp = () => {
    if (Platform.OS === 'android') {
      RNOtpVerify.getOtp()
        .then(() => {
          RNOtpVerify.addListener(otpHandler)
        })
        .catch(() => undefined)
    }
  }

  const otpHandler = (message: any) => {
    if (message !== templates.messageCheckOnTimeOut) {
      if (message != null) {
        // eslint-disable-next-line  @typescript-eslint/no-non-null-assertion
        const otp = /(\d{6})/g.exec(message)![1]
        setAutofetchedOTP(otp)
        return otp
      }
    }
    return undefined
  }

  const removeListener = () => {
    if (Platform.OS === 'android') {
      RNOtpVerify.removeListener()
    }
  }

  return {
    getHash,
    startListeningForOtp,
    otpHandler,
    autoFetchedOTP,
    removeListener,
    setAutofetchedOTP,
  }
}

//calling it inside template

 useEffect(() => {
    getHash()
    startListeningForOtp()
    if (Platform.OS === 'android') {
      if (autoFetchedOTP !== '' && isOTPfetched === false) {
        handleAutoFill()
      }
    }
    return () => {
      removeListener()
    }
  }, [
    getHash,
    startListeningForOtp,
    removeListener,
    autoFetchedOTP,
    handleAutoFill,
    isOTPfetched,
  ])

@shailesh-galgal
Copy link
Author

version - "react-native-otp-verify": "^1.0.5",

@sudeshvs
Copy link

@shailesh-galgal update to the new version 1.1.4

@shailesh-galgal
Copy link
Author

Okay @sudeshvs will try & let you know

@shailesh-galgal
Copy link
Author

@sudeshvs tried didn’t worked

@faizalshap
Copy link
Owner

That's strange issue @shailesh-galgal check android logs if you find any issues there

@shailesh-galgal
Copy link
Author

@faizalshap its working fine inside some of the devices & failing in some of them, the issue explained above is from user's device,will try to find identical phone & share the logs here.

@SanjanaTailor
Copy link

@faizalshap : Same here, Resend OTP is not working to autofill the OTP in boxes it is happening in every device.

@sudeshvs
Copy link

sudeshvs commented Dec 5, 2022

@SanjanaTailor which is your package version ?

@pushpender-singh-ap
Copy link
Contributor

@SanjanaTailor Would you mind sharing a sample project link with us so we can figure out what went wrong.

@m00gl3
Copy link

m00gl3 commented Dec 8, 2022

I wanted to add that on Samsung S21 Android 12, it works great in DEBUG build but in RELEASE it doesn't auto-fill the OTP
This happened both in prev version 1.1.3 and in the new version 1.1.4

I didn't see anything happening in Android Studio logcat while the SMS was received (remember I'm looking in Release)

Also, I put an alert inside the otp handling function: (here, inside otpHandler function) and it didn't fire when the SMS was received.
RNOtpVerify.addListener(otpHandler))

After a while (maybe a minute) - the alert fired with "Timeout Error"

Re-iterating that in DEBUG mode it worked flawlessly.

@Akilramki
Copy link

Akilramki commented Apr 18, 2023

Auto-fill not working for the first time but working on the second time, I able to re-produce this issue every time on the first attempt.
Device: Samsung
Model - SM-J600G

package.json

"react-native-otp-autocomplete": "^1.0.7",

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants