JaDa-ma
JaDa-ma

Reputation: 47

Add data AngularFire offline without loading

I'm creating a PWA using AngularFire. A critical point is to add offline data but it doesn't seem to work.

In my module.app I have set the AngularFirstoreModel.enablePersistence as you can see in the code below:

  imports: [
    BrowserModule,
    FormsModule,
    AppRoutingModule,
    ServiceWorkerModule.register('ngsw-worker.js', {
      enabled: environment.production,
      // Register the ServiceWorker as soon as the app is stable
      // or after 30 seconds (whichever comes first).
      registrationStrategy: 'registerWhenStable:30000',
    }),
    AngularFireModule.initializeApp(environment.firebaseConfig),
    AngularFirestoreModule, //Niet zeker dat dit weg mag
    // Just like that, you're offline enabled!
    AngularFirestoreModule.enablePersistence(),
    AngularFireAuthModule,
  ],

To add the data, I did not do anything special as you can see

 await this.firestore
        .collection('households')
        .add({
          groupname: groepsnaam,
          isDeleted: false,
          idCreator: idCreator,
        })
        .then(
          async (res) => {
            id = res.id;
            await this.firestore
              .collection('households')
              .doc(res.id)
              .collection('leden')
              .doc(idCreator)
              .set({
                idPersoon: idCreator,
              });
          },
          (err) => {
            alert(err);
            return err;
          }
        );

I don't know if it matters I log in with Google Authentication. It gives this error:

Unhandled Promise rejection: Firebase: Error (auth/internal-error). ; Zone: <root> ; Task: HTMLScriptElement.addEventListener:error ; Value: FirebaseError: Firebase: Error (auth/internal-error).

I don't know if I am using it the wrong way or if I have forgotten something.

If you think you can help me, pleas leave a message.

Upvotes: 2

Views: 478

Answers (1)

wonglik
wonglik

Reputation: 1069

I've run into the same issue, and my guess is that you get it when you try to init Firebase while offline.

Upvotes: 1

Related Questions