【发布时间】:2022-01-03 15:07:15
【问题描述】:
我想更新用户配置文件,所以我创建了 Profile js 文件,但无法检索用户数据,因为我没有将用户数据存储在数据库中 那么如何更新活动用户帐户数据名称、电子邮件、照片、密码。所以下面是我的注册用户帐户代码。我是否需要将用户数据存储在数据库中?
注册屏幕
const RegisterScreen = ({ navigation }) => {
const [name, setName] = useState("")
const [email, setEmail] = useState("")
const [password, setPassword] = useState("")
const [image, setImage] = useState(null);
const pickImage = async () => {
// No permissions request is necessary for launching the image library
let result = await ImagePicker.launchImageLibraryAsync({
mediaTypes: ImagePicker.MediaTypeOptions.All,
allowsEditing: true,
aspect: [4, 3],
quality: 1,
});
console.log(result);
if (!result.cancelled) {
setImage(result.uri);
}
};
useLayoutEffect(()=>{
navigation.setOptions({
headerBackTitle:"Back to Login"
});
},[navigation]);
const register = () => {
auth.createUserWithEmailAndPassword(email, password)
.then((authUser) => {
db.collection('users').set(doc(user.uid).set({
displayName: name,
photoURL: image,
password: password,
email: email,
}));
authUser.user.updateProfile({
displayName: name,
photoURL: image
})
})
.catch(error => alert(error.message));
}
return (
<KeyboardAvoidingView behavior='padding' style={styles.container}>
<ScrollView>
<StatusBar style="light" />
<Text h3 style={{ marginBottom: 50 }}>
Create a Signal account
</Text>
<View style={styles.inputContainer}>
<Input
placeholder="Full Name"
autoFocus
type="text"
value={name}
onChangeText={(text) => setName(text)}
/>
<Input
placeholder="Email"
type="email"
value={email}
onChangeText={(text) => setEmail(text)}
/>
<Input
placeholder="Password"
type="password"
secureTextEntry
value={password}
onChangeText={(text) => setPassword(text)}
/>
</View>
<Button buttonStyle={{ backgroundColor: '#49C958ed',}}
containerStyle={styles.button}
raised title="Upload Image" onPress={pickImage} />
<Button buttonStyle={{ backgroundColor: '#49C958ed',}}
containerStyle={styles.button}
raised title="Register"
onPress={register}
/>
</ScrollView>
</KeyboardAvoidingView>
)
}
【问题讨论】:
标签: reactjs firebase react-native firebase-realtime-database firebase-authentication