javascript - 注册后数据未存储在 Firestore 中,但身份验证正在运行
问题描述
谁能说出为什么信息没有存储在 Firestore 中,凭据在注册后反映在身份验证中。我希望用于注册的用户名、电子邮件和密码等相同的详细信息也同时存储在 Firestore 中,但我发送的详细信息并未反映在 Firestore 中。我正在从 TextInput 输入数据并将它们设置为状态。此外,我的 firebase 处于测试模式,因此在我创建的 firestore 中允许读写。我已正确导入索引文件中的设置和配置,并且身份验证也可以正常工作
import {
View,
Text,
Button,
StyleSheet,
TouchableOpacity,
SafeAreaView,
KeyboardAvoidingView,
} from 'react-native';
import CustomTextInput from '../components/CustomTextInput';
import * as firebase from 'firebase';
const SignUp = (props) => {
const [firstName, setFirstName] = useState('');
const [secondName, setSecondName] = useState('');
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const registerUserNoThunk = async () => {
const user = {firstName, secondName, email, password};
try {
const result = await firebase
.auth()
.createUserWithEmailAndPassword(user.email, user.password);
// const data = await result.json();
console.log(result);
console.log(firebase.auth().currentUser.uid, 'userid');
const usersdata = await firebase
.firestore()
.collection('users')
.doc(firebase.auth().currentUser.uid,)
.set({firstName, secondName, email});
console.log(usersdata, 'usersdata');
} catch (error) {
console.log(error);
}
};
return (
<>
<SafeAreaView style={{flex: 1}}>
<KeyboardAvoidingView
style={{flex: 1}}
behavior="height"
keyboardVerticalOffset="10">
<View style={styles.mainview}>
<View style={styles.card}>
<CustomTextInput
label="First Name"
value={firstName}
onChangeText={(text) => {
setFirstName(text);
}}
/>
<CustomTextInput
label="Second Name"
value={secondName}
onChangeText={(text) => {
setSecondName(text);
}}
/>
<CustomTextInput
label="Email"
value={email}
onChangeText={(text) => {
setEmail(text);
}}
/>
<CustomTextInput
label="Password"
value={password}
onChangeText={(text) => {
setPassword(text);
}}
secureTextEntry
/>
{/* <View>
<Button title="Sign Up" onPress={registerUser} />
</View> */}
</View>
<TouchableOpacity
onPress={() => {
props.navigation.navigate('ScreenOne');
}}>
<View>
<Text>Already a member? Login</Text>
</View>
</TouchableOpacity>
<View>
<Button title="Sign Up" onPress={registerUserNoThunk} />
</View>
</View>
</KeyboardAvoidingView>
</SafeAreaView>
</>
);
};
Custom Text Input File
import React from 'react';
import {View, Text, TextInput, StyleSheet} from 'react-native';
const CustomTextInput = (props) => {
return (
<View style={styles.inputcontainer}>
<Text>{props.label}</Text>
<TextInput {...props} style={styles.inputstyle} />
</View>
);
};
const styles = StyleSheet.create({
inputstyle: {
borderBottomWidth: 2,
borderBottomColor: 'grey',
height: 30,
padding: 0,
},
inputcontainer: {marginVertical: '5%', width: '100%'},
});
export default CustomTextInput;
解决方案
推荐阅读
- postgresql - 有没有办法将 EXECUTE query_str 返回的行存储在临时表中或用作子查询?
- python - 无论如何要简单地使用此代码而不是使用常量 if/else 语句?
- power-automate - 如何加快我的 Office 脚本代码,使其不会在 Power Automate 中失败?
- r - 尝试使用 tidyr 取消嵌套 sf 对象时出现问题
- python - 为什么这个正则表达式有效?(贪婪的量词巧妙地停止)
- c# - 在 Windows 上 Nugeting 一个多平台项目
- psychtoolbox - 等待特定时间单击鼠标右键或左键,然后继续
- google-app-engine - HTTP(S) 到特定资源的区域流量路由 - Google Cloud
- javascript - 如何在旋转的圆圈后面居中文本?
- python - 从自定义函数中保存 matplotlib