使用Firebase数据库防止重复的用户,Swift 3 [英] Prevent duplicate users with Firebase Database, Swift 3

查看:143
本文介绍了使用Firebase数据库防止重复的用户,Swift 3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我上传用户名到数据库的代码:

  ref?.child(users)。child(FIRAuth.auth()!. currentUser!.uid).child(username)。setValue .createUserName.text)

这是我试图得到的代码,如果用户名已经存在或而不是

  ref?.child(users)
.queryOrdered(byChild:username)
.queryEqual(toValue:self.createUserName.text?.uppercased())
.observeSingleEvent(of:.value,with:{(snapshot)in

if!snapshot.exists( ){

print(

I try to prevent the creation of already existing usernames.

This is my code where I upload usernames to the database:

ref?.child("users").child(FIRAuth.auth()!.currentUser!.uid).child("username").setValue(self.createUserName.text)

And this is the code where I try to get if the username already exists or not

ref?.child("users")
    .queryOrdered(byChild: "username")
    .queryEqual(toValue: self.createUserName.text?.uppercased())
    .observeSingleEvent(of: .value, with: { (snapshot) in

        if !snapshot.exists() {

            print("
                        

这篇关于使用Firebase数据库防止重复的用户,Swift 3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆