Mat*_*s99 5 firebase react-native firebase-authentication
我需要使用 Firebase 进行电话身份验证,但每次我单击将代码发送给用户的按钮时,都会显示此错误,这可能很容易解决,但由于我对 Firebase 和 React Native 的了解不是很深,所以我无法找到解决方案。
这是我的代码:
export default class VerifyCell extends Component{
static navigationOptions = {header: null}
constructor(props){
super(props);
this.state = {
code: '',
};
}
render(){
const celular = this.props.navigation.getParam('celular');
return (
<ScrollView style={styles.container}>
<HeaderIcon type='MaterialCommunityIcons' name='message-processing'/>
<Text style={styles.titulo}>Phone Verification</Text>
<Text style={styles.dica}>Insert the code that has been sent to you below</Text>
<FormItem onChangeText={ (code) => this.setState({code}) } texto='Code'/>
<View style={{marginBottom: '40%'}}></View>
<GradientButton texto='Send code' onPress={async () => {
const confirmation = await auth().signInWithPhoneNumber('+55 19995661551');
}}/>
<View style={styles.formButton}>
<GradientButton texto='Next' onPress={async () => {
try {
await confirmation.confirm(this.state.code); // User entered code
// Successful login - onAuthStateChanged is triggered
} catch (e) {
console.error(e); // Invalid code
}
this.props.navigation.navigate('CadastraDados', {celular: celular} )
}}/>
</View>
</ScrollView>
)
}
}
Run Code Online (Sandbox Code Playgroud)
我想我需要在代码中的某个位置插入这个“firebase.initializeApp()”。请问,我该如何解决这个问题?
tom*_*fic -7
该错误非常简单,如果您查看文档,您会发现您需要有一个 firebaseConfig 对象,
var firebaseConfig = {
apiKey: "api-key",
authDomain: "project-id.firebaseapp.com",
databaseURL: "https://project-id.firebaseio.com",
projectId: "project-id",
storageBucket: "project-id.appspot.com",
messagingSenderId: "sender-id",
appId: "app-id",
measurementId: "G-measurement-id",
};
Run Code Online (Sandbox Code Playgroud)
与您的应用程序的所有相关数据,然后您需要使用以下命令:
firebase.initializeApp(firebaseConfig);
这通常插入到您的App.js
文件中
归档时间: |
|
查看次数: |
31082 次 |
最近记录: |