diff --git a/__app/component/AutoFillOtp/AutoFillOtp.js b/__app/component/AutoFillOtp/AutoFillOtp.js new file mode 100644 index 0000000..5980bba --- /dev/null +++ b/__app/component/AutoFillOtp/AutoFillOtp.js @@ -0,0 +1,24 @@ +const abortAutoFill = (abort, time) => { + setTimeout(() => { + // abort after two minutes + abort.abort(); + }, time * 60 * 1000); +}; + +const AutoFillOtp = (successCb, failureCb) => { + if ('OTPCredential' in window) { + const abort = new AbortController(); + abortAutoFill(abort, 1); + navigator.credentials.get({ + otp: { transport: ['sms'] }, + signal: abort.signal, + }).then((otp) => { + const { code } = otp; + successCb(code); + }).catch((error) => { + failureCb(error); + }); + } +}; + +export default AutoFillOtp; diff --git a/__app/component/WIP-AutoFillOtp/AutoFillOtp.js b/__app/component/WIP-AutoFillOtp/AutoFillOtp.js deleted file mode 100644 index 8fa59c7..0000000 --- a/__app/component/WIP-AutoFillOtp/AutoFillOtp.js +++ /dev/null @@ -1,7 +0,0 @@ -import React from 'react'; - -export default function AutoFillOtp() { - return ( -
AutoFillOtp
- ); -}