【发布时间】:2019-10-13 12:38:01
【问题描述】:
我需要检查用户名是否已经存在于实时数据库中,然后提示用户选择另一个用户名。它一直说找不到。我认为这是因为我的数据是如何嵌套的。
signup.js
const { email, username, password } = this.state;
await firebase
.auth()
.createUserWithEmailAndPassword(email, password)
.then(async user => {
console.log('Data created', user);
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')
}
})
【问题讨论】:
-
显示用户数据的控制台日志
-
@JuniusL。控制台日志什么也不返回,它转到 else 语句。请帮忙
-
控制台日志
rootRef -
@JuniusL。我将其更改为
let rootRef = firebase.database().ref('users')。我如何在高性能的同时访问/循环所有 uid /account / username。我尝试了 .child(${uid}) 和 .child("account) 但它返回 null。 -
那么
rootRefcotain 是什么意思?
标签: javascript react-native firebase-realtime-database firebase-authentication