How prevent username from duplicate signUp in Firebase? [duplicate]

跟風遠走 提交于 2019-12-06 11:21:52

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!