0

I started with Firebase about 4 days ago. Though I have not being consistent. I want to create a user in the db, though the user was created successfully. After the user creation, it is suppose to return the profile picture page, it fails at this stage.

Being a beginner in this field, I wish to know what I'm to do right.

  adduser(newuser) {
    var promise = new Promise((resolve, reject)=> {
      this.afireauth.auth.createUserWithEmailAndPassword(newuser.email, newuser.password).then(()=> {
        this.afireauth.auth.currentUser.updateProfile({
          displayName: newuser.displayName,
          photoURL: this.mydefaultprofilepic.defaultProfileImage
        }).then(()=> {
          this.firedata.child(this.afireauth.auth.currentUser.uid).set({
            displayName: newuser.displayName,
            photoURL: this.mydefaultprofilepic.defaultProfileImage
          }).then(()=> {
            resolve({success: true})
          }).catch((error)=> {
            reject(error);
          })
        }).catch((error)=> {
          reject(error);
        })
      }).catch((error)=> {
        reject(error);
      })
    })
    return promise;
  }

This is the error I'm getting

ERROR Error: Uncaught (in promise): Error: Reference.set failed: First argument contains undefined in property 'chatusers.AbdvZoGgqwNJcPfOpPKLqmCT1T12.photoURL'
Error: Reference.set failed: First argument contains undefined in property 'chatusers.AbdvZoGgqwNJcPfOpPKLqmCT1T12.photoURL'
    at Object.exports.validateFirebaseData (vendor.js:38911)
    at vendor.js:38957
    at Object.exports.forEach (vendor.js:76671)
    at Object.exports.validateFirebaseData (vendor.js:38940)
    at Object.exports.validateFirebaseDataArg (vendor.js:38899)
    at Reference.set (vendor.js:63235)
    at main.js:45
    at e.g (vendor.js:76794)
    at Eb (vendor.js:76797)
    at Ab (vendor.js:76797)
    at Object.exports.validateFirebaseData (vendor.js:38911)
    at vendor.js:38957
    at Object.exports.forEach (vendor.js:76671)
    at Object.exports.validateFirebaseData (vendor.js:38940)
    at Object.exports.validateFirebaseDataArg (vendor.js:38899)
    at Reference.set (vendor.js:63235)
    at main.js:45
    at e.g (vendor.js:76794)
    at Eb (vendor.js:76797)
    at Ab (vendor.js:76797)
    at c (polyfills.js:3)
    at c (polyfills.js:3)
    at polyfills.js:3
    at t.invokeTask (polyfills.js:3)
    at Object.onInvokeTask (vendor.js:5114)
    at t.invokeTask (polyfills.js:3)
    at r.runTask (polyfills.js:3)
    at o (polyfills.js:3)
    at e.invokeTask [as invoke] (polyfills.js:3)
    at p (polyfills.js:2)
defaultErrorLogger @ vendor.js:1822

I have searched other similar questions on SO but they didn't directly address this situation

halfer
  • 19,824
  • 17
  • 99
  • 186
ken4ward
  • 2,246
  • 5
  • 49
  • 89

1 Answers1

0

(I'm not sure of my answer, it's just a lead, so keep that in mind)

My guess is that you're trying to add some logic where it doesn't belong.

When I talk about firebase authentication, what I see is google sign-in, facebook sign-in ... And e-mail sign-in.

In the case of the two formers, you have a profile picture on your account. Those pictures are your Google+ picture and your Facebook profile picture.

But, in the case of the latter, you don't have a picture.

And in all cases, you aren't able to change the picture. That seems obvious : you can use your account to log in, but you can't manage your account settings in another application. That would cause some serious security issues.

If you want to let your user handle their profile picture, then you should manage documents and storage : when your user signs up to your website, create a document for him. Then, when he wants to change its profile picture, upload the picture to the storage, and put the URL into the document.

Firebase has a very clear distinction between its module : auth is for managing users, firestore is for storing data, and storage is for handling files.