错误:验证器_重置不是一项功能.当尝试使用firebase使用电话登录时,请对本地和Expo进行反应



我正试图在mu react原生应用程序中实现电话登录,但我收到了以下错误:

verifier._reset is not a function. (In 'verifier._reset()', 'verifier._reset' is undefined)
at http://192.168.1.2:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:126633:27 in <unknown>
at node_modules/tslib/tslib.js:60:8 in createExporter
at node_modules/tslib/tslib.js:18:0 in <global>
at http://192.168.1.2:19000/node_modules/expo/AppEntry.bundle?platform=android&dev=true&hot=false&minify=false:116838:35 in rejected

这就是我尝试实现签名的方式:


const SignUp = () => {
const [phoneNumber, setPhoneNumber] = useState("")
const recaptchaVerifier = React.useRef(null);
const auth = getAuth(app)
const sendCode = async () => {
console.log(recaptchaVerifier.current)
signInWithPhoneNumber(auth, phoneNumber, recaptchaVerifier.current!)
.then(r => {
console.log("Hej!")
}).catch(err=>{
console.log(err)
})
}
return (
<SafeAreaView
style={tw.style('w-full')}>
<FirebaseRecaptchaVerifierModal
ref={recaptchaVerifier}
firebaseConfig={app.options}
attemptInvisibleVerification={true}
/>
<TextInput
style={tw.style('w-1/2', 'shadow', 'border', 'rounded', 'py-2', 'px-3', 'text-gray-700')}
onChangeText={setPhoneNumber}
keyboardType="phone-pad"
/>
<Button title={"Send Code"} onPress={sendCode}/>
</SafeAreaView>
)
}
export default SignUp

我也尝试过这样实现它:const phoneProvider = new PhoneAuthProvider(auth) const verificationId = await phoneProvider.verifyPhoneNumber(phoneNumber, recaptchaVerifier.current!)但我得到了同样的结果。

我完全没有主意,所以任何帮助都将不胜感激。

更新到最新版本的expo-firebase-recaptcha应该可以修复它。

打开此文件:node_modulesexpo-firebase-recaptchabuildFirebaseRecaptchaVerifier.js并添加

export default class FirebaseRecaptchaVerifier {
token;
constructor(token) {
this.token = token;
}
get type() {
return 'recaptcha';
}
async verify() {
return this.token;
}
async _reset(){
}
}

在那里添加_reset((函数并保存它!错误将被修复。

这个答案很接近,但即使在修补了包之后,我也遇到了同样的问题。这似乎是最近的一个问题,OP使用的是模态形式,而不是原始验证器。

相反,在第31行附近的node_modules/expo-firebase-recaptcha/build/firebase-RecaptchaVerifierModel.js中添加以下内容:


async _reset() {
return
}

只要更新您的expo包,它就已经解决了。(见此处(

最新更新