在Expo(React原生)应用程序中自动检测Otp

jqjz2hbq  于 2023-03-19  发布在  React
关注(0)|答案(1)|浏览(143)

我试图在我的react-native expo应用程序中实现自动检测Otp功能,我正在使用“react-native-otp-verify”库,但出现链接错误。
代码

import { useEffect, useState } from "react"
import { StyleSheet, Text, View } from "react-native"
import { useOtpVerify } from "react-native-otp-verify"
import Button from "../component/Button"
import Input from "../component/Input"
import { setLoggedInResponse, useStore } from "../Store/Store"

const Otp = ({ moveToNextScreen }) => {
    const [otp, setOtp] = useState(undefined)
    const [otpText, setOtpText] = useState('')
    const [err, setError] = useState(undefined)
    const { mobile } = useStore()
    const { otp: OtpCode } = useOtpVerify({ numberOfDigits: 6 })
    const verifyOtp = ({ otp }) => {
        fetch("https://web.com/api/v1/verify_otp", {
            method: "POST",
            headers: {
                Accept: 'application/json',
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                mobile,
                otp
            })
        }).then((res) => res.json())
            .then(res => {
                console.log(res)
                if (res.status.result) {
                    moveToNextScreen()
                    setLoggedInResponse(res.data)
                }
                else setError(res.status.message)
            })
            .catch(err => {
                console.log(err)
                setError(err)
            })
            .finally(() => {
                setOtp('')
            })
    }

    const handleClick = () => {
        setError(undefined)
        setOtp(otpText)
    }

    useEffect(() => {
        if (otp)
            verifyOtp({ otp })
        else if (OtpCode)
            verifyOtp({ otp: OtpCode })
    }, [otp, OtpCode])
    return (
        <View style={styles.container}>
            <Input autoFocus={true} autoComplete="sms-otp" textContentType="oneTimeCode" value={otpText} onChange={setOtpText} style={{ textAlign: "center" }} placeholder={"Enter Otp"} />
            <Button title="Submit" onClick={handleClick} />
            {err && <Text style={styles.error}>{JSON.stringify(err)}</Text>}
        </View>
    )
}

export default Otp

错误
错误错误:软件包'taxza.exe'似乎没有链接。请确保:

  • 安装程序包后重新构建了应用程序
  • 您未使用Expo托管工作流js引擎:爱马仕ERROR不变量冲突:“main”尚未注册。这可能发生在以下情况下:
  • Metro(本地开发服务器)从错误的文件夹运行。检查Metro是否正在运行,停止它并在当前项目中重新启动它。
  • 由于发生错误,模块加载失败,并且未调用AppRegistry.registerComponent。,js engine:爱马仕

由于我们无法在expo app中手动链接,有什么方法可以解决这个问题吗?

相关问题