Firebase storage using new ddbb

I’ve got a Firebase login with Facebook working properly and I’d like to create one collection with different values, each of them with an ID which would be the user ID.

So far I found some ways to create these values but either way there are not related with the user or is using the old ddbb (realtime one). This new ddbb still on beta and there is not too much documentation with Ionic.

How can I archive this?

Hmm could you expand a little more on what you’re trying to accomplish?

If all you want it to create a document on the FireStore database to save the user data you can do it after user creation using the user’s uid.

This is a bit general, but might look something like this:

async createUser(
    email: string,
    password: string
  ): Promise<firebase.User> {
  const newUser: firebase.User = await this.afAuth.auth.createUserWithEmailAndPassword(
    email,
    password
  );

  const userProfileDocument: AngularFirestoreDocument<
    userProfile
  > = this.fireStore.doc(`userProfile/${newUser.uid}`);

  await userProfileDocument.set({
    id: newUser.uid,
    email: email,
    // Other info you want to add
  });

  return newUser;
}

Note that on that example I’m using async/await syntax.

I use Facebook login:

facebookLogin() {
    if (this.platform.is('cordova')) {
      return this.facebook.login(['email', 'public_profile']).then(res => {
        const facebookCredential = firebase.auth.FacebookAuthProvider.credential(res.authResponse.accessToken);
        return firebase.auth().signInWithCredential(facebookCredential)
          .then(success => {
            console.log('Firebase success: ' + JSON.stringify(success));
          }).catch((error) => { console.error(error) });
      });
    } else {
      let loading = this.loadingCtrl.create({
        content: 'Please wait...'
      });

      loading.present();
      const that = this;
      return this.AngularFireAuth.auth
        .signInWithPopup(new firebase.auth.FacebookAuthProvider())
        .then(function (res) {
          that.logged = true;
          loading.dismiss();
        })
        .catch(function (error) {
          loading.dismiss();
        });
    }

With this the user is also create on my ddbb.
So let’s say now that on a different page, with this user logged I want to create a new element on my collection that I already created using Cloud Firestore:


So the collection would be something like this:

sets: [
{
  userID1: {...}
},
{
  userID2: {...}
}
]

I extended Angular Firestore with a provider that has methods like ReadDocumentOnce, UpsertDocument, DownloadCollectionOnce, DownloadCollectionAndListenForValueChanges. So I only had to struggle with the AngularFire2 Firestore API in that one place, and everywhere else in the app I inject my extended provider.

Do you have any documentation about this?