【发布时间】:2021-09-07 03:23:36
【问题描述】:
我想知道为什么在我的 Android 设备上测试 Expo Go 上的应用程序时,我的数据没有存储在 Firebase 数据库中。 在 Web 浏览器上测试时的 data is still being stored normally
这是代码
import React, { Component } from 'react'
import { View, Button, TextInput, StyleSheet, TouchableOpacity, Text } from 'react-native'
import firebase from 'firebase'
import "firebase/firestore";
export class Register extends Component {
constructor(props) {
super(props);
this.state = {
email: '',
password: '',
firstname: '',
lastname:'',
city:'',
province:'',
}
this.onSignUp = this.onSignUp.bind(this)
}
onSignup() 函数
onSignUp() {
const { email, password, firstname, lastname, city, province } = this.state;
firebase.auth().createUserWithEmailAndPassword(email, password)
.then((result) => {
const user = firebase.auth().currentUser;
firebase.firestore().collection("users")
.doc(user.uid)
.set({firstname,lastname,city,province,email})
user.sendEmailVerification
console.log(result)
})
.catch((error) => {
console.log(error)
})
}
数据输入(只显示电子邮件,因为它们都是一样的)
<View style={styles.textBoxView}>
<TextInput
style={styles.textBox}
placeholder="E-mail"
onChangeText={(email) => this.setState({ email })}/>
<View style={styles.space}></View>
</View>
哦,还有注册按钮
<View style={styles.buttons}>
<TouchableOpacity onPress={() => this.onSignUp()}>
<Text style={styles.textElement}>Sign up</Text>
</TouchableOpacity>
</View>
【问题讨论】:
-
嘿,我已经发布了答案。如果您认为这对您有帮助,您可以通过单击对勾图标接受它,以便其他人知道问题已解决,否则请随时提出更多问题。
标签: javascript react-native google-cloud-firestore firebase-authentication