check if a user already exists firebase realtime database react native

Solutions on MaxInterview for check if a user already exists firebase realtime database react native by the best coders in the world

showing results for - "check if a user already exists firebase realtime database react native"
Andrea
19 Nov 2018
1const { email, username, password } = this.state;
2
3let rootRef = firebase.database().ref();
4
5rootRef
6  .child('users')
7  .orderByChild('username')
8  .equalTo(username)
9  .once('value')
10  .then(snapshot => {
11    if (snapshot.exists()) {
12      let userData = snapshot.val();
13      console.log(userData);
14      Alert.alert('username is taken');
15      return userData;
16    } else {
17      console.log('not found');
18      firebase
19        .auth()
20        .createUserWithEmailAndPassword(email, password)
21        .then(async user => {
22          console.log('Data created', user);
23        });
24    }
25});
26