How prevent username from duplicate signUp in Firebase?

This question already has an answer here:

  • Firebase android : make username unique 3 answers

  • If you are trying to prevent duplicate Firebase usernames, that can be done right at the createUser stage.

    Assume a dialog is presented to new user asking to create an account: this will get their desired userName and password.

    Send that to createUser and if there's an error (because it already exists) notify them and ask for a different userName:

        myRootRef.createUser(email, password: pw, withValueCompletionBlock: { error, result in
    
            if error != nil {
                self.errMsgField.stringValue = "email/username in use, try again"
    
            } else {
                let uid = result["uid"] as! String //the uid of the new user
                print("user created as  (uid)")
                self.authUserWithAuthData( email, password: pw ) //auth the user
            }
        })
    

    After the user is created you would probably add their info the /users node as well.

    链接地址: http://www.djcxy.com/p/84216.html

    上一篇: 访问Firebase规则中的电子邮件地址

    下一篇: 如何防止用户名在Firebase中重复注册?