Firebase 电话身份验证,缺少客户端标识符

问题描述 投票:0回答:0

我目前正在尝试使用 react-native-firebase 库为我的 react-native expo 应用程序实施电话身份验证。

使用用户名和密码的普通身份验证工作正常。但是我需要为我的应用程序实施电话身份验证。

我有以下代码:

import {
  Text, View, KeyboardAvoidingView, TouchableOpacity,
} from "react-native";
import React, { useEffect } from "react";
import { useNavigation } from "@react-navigation/native";
import auth from "@react-native-firebase/auth";
import styles from "../../styles/base";

function RegisterScreen() {
  const navigation = useNavigation();

  useEffect(() => {
    const unsubscribe = auth().onAuthStateChanged((user) => {
      if (user) {
        navigation.replace("Authenticated");
      }
    });
    return unsubscribe;
  }, []);

  const handleSignUp = () => {
    console.log(auth().settings.appVerificationDisabledForTesting);
    auth().signInWithPhoneNumber("*************").then(() => {
      console.log("successfull");
    }).catch((error) => {
      console.log(error);
      console.log("error");
    });
  };

  return (
    <KeyboardAvoidingView
      style={styles.container}
      behavior="padding"
    >
      <View style={styles.buttonContainer}>
        <TouchableOpacity
          onPress={handleSignUp}
          style={styles.button}
        >
          <Text style={styles.buttonText}>Register</Text>
        </TouchableOpacity>
      </View>
      <View>
        <Text style={styles.accountText} onPress={() => navigation.replace("Login")}>I already have an account.</Text>
      </View>

    </KeyboardAvoidingView>
  );
}

export default RegisterScreen;

我已经硬编码了一个我有权访问的电话号码,但是当我尝试使用这个号码登录时,我收到以下错误:

[Error: [auth/missing-client-identifier] This request is missing a valid app identifier, meaning that neither SafetyNet checks nor reCAPTCHA checks succeeded. Please try again, or check the logcat for more details.]

我知道我必须实施安全网或 reCAPTCHA。问题是谷歌指南已经过时(一些链接已被弃用)并且没有提供任何代码示例。我更喜欢 reCAPTCHA,因为我需要该应用程序在 android 和 IOS 上运行。 我到处搜索,但我找不到任何关于如何实现它的例子。出于手动测试的目的,我什至尝试过:

auth().settings.appVerificationDisabledForTesting = true;

但这也不能解决问题。我试图自己实现 reCAPTCHA,因为我找不到任何好的例子,但我做不到。我使用了以下依赖项和指南:https://docs.expo.dev/versions/v47.0.0/sdk/firebase-recaptcha/

我真的很想看到一个使用我使用的包的工作示例。

android ios firebase react-native react-native-firebase
© www.soinside.com 2019 - 2024. All rights reserved.