[英]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.