如何检查Firebase中是否存在用户名

时间:2016-10-08 02:47:38

标签: ios swift firebase firebase-realtime-database firebase-authentication

I have the following structure in my Firebase:

users ->
         uid ->
               provider: "facebook.com"
               username: "vandanpatel"

当我登录用户时,我只想检查他是否已经设置了用户名。我有获得当前用户的机制。我只想检查当前用户是否有“用户名”字段。我尝试了一切,但似乎没有什么对我有用。如果他们没有“用户名”字段,我会让他们选择“用户名”并设置它。

1 个答案:

答案 0 :(得分:0)

您可以尝试: -

    FIRDatabase.database().reference().child("users/\(FIRAuth.auth()!.currentUser!.uid)/username").observeSingleEvent(of: .value, with: {(snap) in

        if snap.exists(){

            //Your user already has a username

        }else{

            //You need to set the user's name and the the required segue

        }
    })

另请查看此链接: - Check if username already exists

相关问题