John Leonardo
John Leonardo

Reputation: 598

Firebase creating multiple accounts when I have it set to one-per-email

There is a bug that's happening in my app. I suspect it has something to do with slow internet connection, and since the user isn't getting a response, they keep hitting the sign up button. I'll go look in the DB, and see like 12 accounts for the same email all signed up the same time. How do you guys handle this? Is there a way I can do a spinner until the Firebase login/createAccount method is finished?

Upvotes: 0

Views: 525

Answers (1)

Dravidian
Dravidian

Reputation: 9945

Firstly change your one account per email address to yes.

When your user presses the button to create an account , you need to trigger the createUser but before that you need to disable the button itself to avoid the further calls from the same user with same details

func createMyUser(sender:UIButton!){ 

 sender.isEnabled = false 
 FIRAuth.auth()?.createUser(withEmail: emailTextField.text!, password: passwordTextField.text!, completion: { (user, err) in
   ....
    }

Now if you encounter any error even the network error handle that error with errorCodeNetworkError. And show the user an alert stating a network error has occurred.

if let firebaseError = FIRAuthErrorCode(rawValue: err!._code) {

                    switch firebaseError{

                    case .errorCodeEmailAlreadyInUse : sender.isEnabled = true
                                                         break

                    case .errorCodeNetworkError :        print("Network Error occured!")

                                                         sender.isEnabled = true
                                                         break
                    default : .....

        }}

Upvotes: 1

Related Questions