0

I have an angular app with a firbase backend. First i added firebase via Webversion 8. Now i want to implement it with angular/fire.

This is how it added with ng add:

imports: [
    provideFirebaseApp(() => initializeApp(environment.firebaseConfig)),
    provideAuth(() => getAuth()),
    provideFirestore(() => {
      const firestore = getFirestore();
      enableIndexedDbPersistence(firestore).catch(e => console.error);
      return firestore;
    }),
]

For auth i have also an auto login function:

public autoLogin(): any {
  this.store.dispatch(new AppActions.Splash(true));
  const currentUser = this.auth.currentUser;
...

But this.auth.currentUseis not defined after reload. How do i handle autologin with this version? Can't i save the user, that on next start it's saved in this.auth?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Jonathan Sigg
  • 306
  • 3
  • 12
  • Restoring the user data takes a call to the server so is an asynchronous operation. To detect the result of that operation, use an auth state listener as shown in the questions I linked or in the first docs snippet of the documentation on [getting the current user](https://firebase.google.com/docs/auth/web/manage-users#get_the_currently_signed-in_user). – Frank van Puffelen Apr 21 '23 at 13:54

0 Answers0