📌  相关文章
📜  检查用户是否已经存在 firebase 实时数据库 react native - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:24.531000             🧑  作者: Mango

代码示例1
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);
        });
    }
});