[
]
I have 3 recording screens and I want to list user information on a single page.But each is assigned a separate pushKey. I also can't use these pushKeys to access the database in the code section
{
const user = firebase.auth().currentUser.uid;
const db = firebase.database();
const ref = db.ref('kullaniciBilgiler/'+`${user}`);
ref.once('value', (snapshot) => {
var data=snapshot.val();
console.log(data)
}, (errorObject) => {
console.log('The read failed: ' + errorObject.name);
});
export default class profile extends Component {
constructor(props) {
super(props);
this.state = {
};
}
render() {
var box = [];
for(let i = 0; i <= 5; i++){
box.push(
<View style={{flexDirection:'row'}}>
<View style={styles.textBox}>
<Text style={styles.textMid}>Soyisim</Text>
</View>
<View style={styles.inputView}>
<TextInput
onChangeText={(text)=>setList(text)}
style={styles.input}
/>
</View>
</View>
)
}
return (
<ScrollView>
<SafeAreaView style={styles.container} >
<View style={styles.profilePhoto}>
<Image
style={{
width: 100,
height: 100,
resizeMode: 'contain',
marginTop:40
}}
source={
require('../../image/logo.png')
}
/>
</View>
<View style={styles.profileDetails}>
{box}
</View>
</SafeAreaView>
</ScrollView>
);
}
}
}
I can't get random keys assigned by push and I can't access information from the database
[
]
_handleSubmit = (values) => {
auth()
.createUserWithEmailAndPassword(values.email, values.password)
.then(() => {
userId = firebase.auth().currentUser.uid;
if (userId) {
var database = firebase.database().ref('kullaniciBilgiler/').child(userId).push();
database.set({
name: values.name,
surname: values.surname,
email: values.email,
}).then(() => console.log('okey'));
}
This register code
When a new user is created by createUserWithEmailAndPassword, set all of user's data right under the UID node instead of pushing new nodes. This can be done by using set() instead of push():
const userId = firebase.auth().currentUser.uid;
const database = firebase.database().ref('kullaniciBilgiler/' + userId)
database.set({
name: values.name,
surname: values.surname,
email: values.email,
}).then(() => console.log('okey'));
// similarly use 'update()' when adding other fields later
When you query user's node, it should now return an object like this:
{
name: '',
surname: '',
email: '',
age: 0,
...otherFields
}
You can read more about updating data in the documentation.