Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uncaught exception 'InvalidPathValidation', reason: '(child:) Must be a non-empty string and not contain '.' '#' '$' '[' or ']''

I'm making an authentication for my app but getting an error 'invalidPathValidation' when I tap the sign up button.

From my research I think it is something related to the characters in the email which are not accepted by Firebase.

@IBAction func signUpButtonPressed(_ sender: Any) {
    guard emailAddress.text != "" , password.text != ""
        else {
            errorOutlet.isHidden = false
            return errorOutlet.text = "Email or Password field is empty."
    }

    if password.text != "" , emailAddress.text != "" {
        Auth.auth().createUser(withEmail: emailAddress.text! , password: password.text!, completion: { (user, error) in
            if let error = error {
                print(error.localizedDescription)
                self.errorOutlet.isHidden = false
                return self.errorOutlet.text = "couldn't create account"
            }

            if let user = user {
                let changeRequest = Auth.auth().currentUser!.createProfileChangeRequest()
                changeRequest.displayName = self.firstName.text!
                changeRequest.commitChanges(completion: nil)

                let imageRef = self.userStorage.child("\(user.uid).jpg")
                let data = UIImageJPEGRepresentation(self.profileImage.image!, 0.6)
                let uploadTask = imageRef.putData(data! , metadata: nil, completion: { (metadata, err) in
                    if err != nil {
                        print(err!.localizedDescription)

                        // an err occured
                        self.errorOutlet.isHidden = false
                        return self.errorOutlet.text = "error"
                    }

                    imageRef.downloadURL(completion: { (url , er) in
                        if er != nil{
                            print(er!.localizedDescription)

                            // an error occured
                            self.errorOutlet.text = "error"
                            return  self.errorOutlet.isHidden = false

                        }

                        if let url = url {
                            let userInfo : [String : Any] = ["uid" : user.uid ,
                                                             "first Name" : self.firstName.text! ,
                                                             "last name" : self.surName.text! ,
                                                             "urlToImage" :url.absoluteString]

                            self.ref.child("users").child("user.uid").setValue(userInfo)

                            let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "subscribe")
                            self.present(vc, animated: true, completion: nil)
                        }
                    })
                })

                uploadTask.resume()
            }
        })
    }
}
like image 848
user00007 Avatar asked Sep 01 '25 02:09

user00007


1 Answers

It seems like this line is problematic:

self.ref.child("users").child("user.uid").setValue(userInfo)

You're treating the child "user.uid" as string (Which includes the problematic ".", which cannot be used as a key).

Instead, use userInfo.uid, without the "".

like image 88
Gal Shahar Avatar answered Sep 02 '25 16:09

Gal Shahar