简体   繁体   English

如何在手机身份验证中显示 reCaptcha firebase react native

[英]how to show reCaptcha in phone authentication firebase react native

When I'm going to authenticate with phone number I get this error当我要使用电话号码进行身份验证时,出现此错误在此处输入图像描述

how can I use reCaptcha I can't use safe.net Method in phone authentication because my country is not exist when I want to create google cloud account.我如何使用 reCaptcha 我不能在手机身份验证中使用 safe.net 方法,因为当我想创建谷歌云帐户时我的国家不存在。 this is my code.这是我的代码。

please help me and if you have a good doc for solving this problem send me its link请帮助我,如果您有解决此问题的好文档,请将其链接发送给我

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

const firebaseConfig = {
  apiKey: 'xxxxxxxxxxxx',
  authDomain: 'xxxxxxxxxxxxx',
  projectId: 'xxxxxxxxxxxxx',
  storageBucket: 'xxxxxxxxxxxxxx',
  messagingSenderId: 'xxxxxxxxxxxxx',
  appId: 'xxxxxxxxxxxxxxx',
  measurementId: 'xxxxxxxxxxxxxx',
};

if (!firebase.apps.length) {
  firebase.initializeApp(firebaseConfig);
}

export default () => {
  return { firebase, auth };
};

const SignUPScreen = ({ navigation }) => {
  const { auth } = firebaseSetup();
  const [confirm, setConfirm] = useState(null);
  const [phoneNumber, setPhoneNumber] = useState('');
  const signIn = async () => {
    try {
      const confirmation = await auth().signInWithPhoneNumber(phoneNumber);
      setConfirm(confirmation);
      navigation.navigate('OTP', { confirm: confirm });
    } catch (error) {
      alert(error);
    }
  };
  return (
    <View style={styles.container}>
      <TextInput
        style={styles.textInput}
        placeholder="Enter your phone number"
        keyboardType="phone-pad"
        onChangeText={(text) => setPhoneNumber(text)}
      />
      <Button title="Sign Up" onPress={() => signIn()} />
    </View>
  );
};
import { useState } from 'react';
import { Alert, Button, StyleSheet, View } from 'react-native';
import { TextInput } from 'react-native-paper';

const OTP = ({ route }) => {
  const { confirm } = route.params;
  const [code, setCode] = useState('');
  const confirmCode = async () => {
    try {
      await confirm.confirm(code);
      Alert.alert('User sign in SuccessFully');
    } catch (error) {
      Alert.alert('Invalid code');
    }
  };
  return (
    <View style={styles.container}>
      <TextInput
        style={styles.textInput}
        placeholder="Enter the OTP code"
        value={code}
        onChangeText={(text) => setCode(text)}
      />
      <Button title="Confirm Code" onPress={() => confirmCode()} />
    </View>
  );
};

I found that the problem is due to SHA1.我发现问题是由于 SHA1。
I had filled in an wrong SHA1 key in the Firebase console.我在 Firebase 控制台填写了错误的 SHA1 密钥。
I change it with correct SHA1 then the error have been gone.我用正确的 SHA1 更改它,然后错误就消失了。

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

相关问题 如何在 expo 上使用 firebase 电话 aut(反应原生 2022) - how to use firebase phone aut on expo (react native 2022) Expo react-native app with firebase phone authentication works on web, error on ios simulator and crashes with no warning on Android - Expo react-native app with firebase phone authentication works on web, error on ios simulator and crashes with no warning on Android 反应本机。 如何根据用户身份验证状态显示屏幕 - React Native. How to show screens according to the User Authentication status 将身份验证数据保存到 firebase React native - save Authentication data to firebase React native 如何将电话号码与 firebase 实时数据库中的电话号码匹配(react-native) - How to match phone number with the phone number present in firebase real-time database (react-native) 如何在 Firebase 中使用电子邮件和电话进行身份验证? - How to use email and phone to authentication in Firebase? 如何使用 Firebase 在 Flutter 中进行电话身份验证? - How to do Phone Authentication in Flutter using Firebase? Firebase 身份验证对 React Native auth.tenandId 错误 - Firebase authentication on React Native auth.tenandId error React Native,堆栈导航组 Firebase 身份验证保持登录状态 - React Native, Stack Navigation Group for Firebase authentication stay logged in 将 Firebase 电话身份验证与协程一起使用 - Use Firebase Phone Authentication with Coroutines
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM