gpt4 book ai didi

ios - 如何防止用户名在 Firebase 中重复注册?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:00:51 26 4
gpt4 key购买 nike

<分区>

我想在注册用户输入的内容时防止重复的用户名。我创建了如下所示的电子邮件登录,首先是 createUser,然后使用用户字典对其 setValue 进行授权。

但我与 Firebase 安全设置以及如何检查处理这种情况有关。

REF_BASE.createUser(email, password: pwd, withValueCompletionBlock: { ..

REF_BASE.authUser(email, password: pwd, withCompletionBlock: { ..

REF_USERS.childByAppendingPath(uid).setValue(user)

这种处理总是响应错误。

REF_USERS.childByAppendingPath(uid).childByAppendingPath("username").setValue(user["username"]) { (error: NSError!, result: Firebase!) in
if error != nil {
print(error.localizedDescription)
}
else {
self.REF_USERS.childByAppendingPath(uid).setValue(user)
}
}

这是我的安全规则,我怎样才能修复一切以防止重复用户?

"users": {
".read": "auth !== null",
"$user": {
"username": {
".read": "auth !== null",
".write": "newData.val() === auth.uid && !data.exists()"
}
}
},

Update:

根据 Frank 的回答,但我不知道在这种情况下注册新用户时需要做什么。

app : {
users: {
"some-user-uid": {
email: "test@test.com"
username: "myname"
}
},
usernames: {
"myname": "some-user-uid"
}
}

我需要为两个不同的节点同时添加相同的用户 uid 吗?如果有人用 Swift 解释它。那就太好了。

"users": {
"$uid": {
".write": "auth !== null && auth.uid === $uid",
".read": "auth !== null && auth.provider === 'password'",
"username": {
".validate": "
!root.child('usernames').child(newData.val()).exists() ||
root.child('usernames').child(newData.val()).val() == $uid"
}
}
}

无法将新用户 信息添加到用户名 父节点。是否需要其他安全规则?

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com