check if a user already exists firebase realtime database react native

The solution for “check if a user already exists firebase realtime database react native” can be found here. The following code will assist you in solving the problem.

const { email, username, password } = this.state;

let rootRef = firebase.database().ref();

rootRef
.child(‘users’)
.orderByChild(‘username’)
.equalTo(username)
.once(‘value’)
.then(snapshot => {
if (snapshot.exists()) {
let userData = snapshot.val();
console.log(userData);
Alert.alert(‘username is taken’);
return userData;
} else {
console.log(‘not found’);
firebase
.auth()
.createUserWithEmailAndPassword(email, password)
.then(async user => {
console.log(‘Data created’, user);
});
}
});

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in