Javascript React本机Firebase电话身份验证-身份验证/会话过期错误。(安卓)

Javascript React本机Firebase电话身份验证-身份验证/会话过期错误。(安卓),javascript,reactjs,firebase,react-native,react-native-firebase,Javascript,Reactjs,Firebase,React Native,React Native Firebase,这是我来自rnfirebase.io的代码 我在按下登录按钮后收到短信代码。但在键入验证码后,firebase会向我返回此[auth/session expired]错误 [错误:[身份验证/会话已过期]sms代码已过期。请重新发送验证代码以重试。] 另外,设置确认(confirmation)不起作用。它再次返回空值 我怎样才能解决这个问题?谢谢 import React, { useState } from "react"; import { View, Text, Sty

这是我来自rnfirebase.io的代码

我在按下登录按钮后收到短信代码。但在键入验证码后,firebase会向我返回此[auth/session expired]错误

[错误:[身份验证/会话已过期]sms代码已过期。请重新发送验证代码以重试。]

另外,设置确认(confirmation)不起作用。它再次返回空值

我怎样才能解决这个问题?谢谢

import React, { useState } from "react";
import { View, Text, StyleSheet, Button, TextInput } from "react-native";
import auth from "@react-native-firebase/auth";
import colors from "../../config/colors";
// create a component
const UyeOlScreen = () => {
 // If null, no SMS has been sent
 const [confirm, setConfirm] = useState(null);

 const [code, setCode] = useState("");

 // Handle the button press
 async function signInWithPhoneNumber(phoneNumber) {
   const confirmation = await auth().signInWithPhoneNumber(phoneNumber);
   setConfirm(confirmation);
 }

 async function confirmCode() {
   try {
     await confirm.confirm(code);
   } catch (error) {
     console.log(error);
   }
 }

 if (!confirm) {
   return (
     <Button
       title="Phone Number Sign In"
       onPress={() => signInWithPhoneNumber(`+123456789`)}
     />
   );
 }

 return (
   <>
     <TextInput value={code} onChangeText={(text) => setCode(text)} />
     <Button title="Confirm Code" onPress={() => confirmCode()} />
   </>
 );
};
//make this component available to the app
export default UyeOlScreen; ```
import React,{useState}来自“React”;
从“react native”导入{视图、文本、样式表、按钮、文本输入};
从“@react native firebase/auth”导入身份验证;
从“../../config/colors”导入颜色;
//创建一个组件
const UyeOlScreen=()=>{
//如果为空,则未发送短信
const[confirm,setConfirm]=useState(null);
const[code,setCode]=useState(“”);
//按按钮
异步函数signInWithPhoneNumber(phoneNumber){
const confirmation=wait auth().signInWithPhoneNumber(phoneNumber);
设置确认(确认);
}
异步函数confirmCode(){
试一试{
等待确认。确认(代码);
}捕获(错误){
console.log(错误);
}
}
如果(!确认){
返回(
使用电话号码(`+123456789`)登录
/>
);
}
返回(
设置代码(文本)}/>
confirmCode()}/>
);
};
//使此组件可用于应用程序
导出默认屏幕```

这帮助我解决了这个问题:

当然,我必须做一些调整,使它为我工作。具体来说,我拿出了代码:

firebase
  .firestore()
  .collection('users')
  .where('phoneNumber', '==', this.state.phoneNumber)
  .get()
  .then((querySnapshot) => {
    if (!querySnapshot.empty) {
      // User found with this phone number.
      throw new Error('already-exists');
    }
我认为这是在处理可以与我不使用的firebase一起使用的存储

我还提出:

let fbWorkerApp = firebase.apps.find(app => app.name === 'auth-worker')
                 || firebase.initializeApp(firebase.app().options, 'auth-worker');
  fbWorkerAuth = fbWorkerApp.auth();  
  fbWorkerAuth.setPersistence(firebase.auth.Auth.Persistence.NONE); // disables caching of account credentials
只是用“auth()”来代替fbWorkerAuth,因为我已经在做:

import auth from '@react-native-firebase/auth';
另外,在一个catch块中有一个小bug,它有“err”,应该是“error”

否则它就为我解决了这个问题。遗憾的是,所有与此相关的文档都指向了一个不起作用的示例