简体   繁体   English

React Native Firebase Phone Auth - auth/session-expired 错误。 (安卓)

[英]React Native Firebase Phone Auth - auth/session-expired error. (Android)

This is my code from rnfirebase.io.这是我来自 rnfirebase.io 的代码。

I receive the SMS code after pressing the sign-in button.按下登录按钮后,我收到了 SMS 代码。 But after typing the Verification code, firebase returns me this [auth/session-expired] error.但是在输入验证码后,firebase 给我返回了这个 [auth/session-expired] 错误。

[Error: [auth/session-expired] The sms code has expired. [错误:[auth/session-expired] 短信代码已过期。 Please re-send the verification code to try again.]请重新发送验证码重试。]

Also setConfirm(confirmation) does not works. setConfirm(confirmation) 也不起作用。 It returns a null again.它再次返回 null。

How can I solve this problem?我怎么解决这个问题? Thanks!谢谢!

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; ```

This helped me fix this issue: How to use Firebase's 'verifyPhoneNumber()' to confirm phone # ownership without using # to sign-in?这帮助我解决了这个问题: How to use Firebase's 'verifyPhoneNumber()' to Confirm phone # Ownership without using # to sign-in?

Of course, I had to make a few tweaks to make it work for me.当然,我必须进行一些调整才能使其适合我。 Specifically, I took out the code:具体来说,我拿出了代码:

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');
    }

I think that is dealing with storage that can be used with firebase that I do not use.我认为这是处理可以与我不使用的 firebase 一起使用的存储。

I also took out:我还拿出来:

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

and just used "auth()" in place of fbWorkerAuth because I was already doing:并且只是使用“auth()”代替 fbWorkerAuth,因为我已经在做:

import auth from '@react-native-firebase/auth';

Also there is a small bug in one of the catch blocks that has "err" and it should be "error".在其中一个具有“错误”的 catch 块中还有一个小错误,它应该是“错误”。

Otherwise it solved this issue for me.否则它为我解决了这个问题。 Too bad all of the documentation around this is pointing us to a sample that doesn't work!太糟糕了,所有与此相关的文档都将我们指向一个不起作用的示例!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM