Firestore Angular2 Получение документов на основе текущего пользователя - PullRequest
0 голосов
/ 25 мая 2020

Я начал разработку мобильного приложения, используя IONI C, ANGULAR против Google Firestore. Это приложение будет использовать в основном документы на основе текущего пользователя, и большинство моих запросов мне нужно будет передать этому пользователю. Однако у меня возникают проблемы с получением документов из firestore с использованием следующего кода из моей службы на страницу:

user-profile.service.ts

async get(){      
      // await this.afAuth.user.subscribe(currentUser => {
      //   if(currentUser){      
      //     this.userId = currentUser.uid;
      //     console.log("User Current ID: " + this.userId);

       console.log("PP:" +this.afAuth.auth.currentUser.uid)
          return this.userProfilesCollection.doc<UserProfile>(this.afAuth.auth.currentUser.uid).snapshotChanges().pipe(
            map(doc => {
                    const id = doc.payload.id;
                    const data = doc.payload.data();
                    return{id, ...data };
                  }
                )
            );
}

landing-page.page.ts

export class LandingPage implements OnInit {
  userProfile : UserProfile;

  constructor(
    private authService : AuthService,
    private loadingController : LoadingController,
    private userProfileService: UserProfileService,
    private router : Router
  ) {
   }

  ngOnInit() {
      this.loadUserProfile();
  }

  async loadUserProfile()                                                  {
    const loading = await this.loadingController.create({
      message: 'Loading user profile'
    });
    await loading.present();

    this.userProfileService.get().then(res=>{
      console.log(res);
      loading.dismiss();
    })
    // this.userProfileService.get().then(
    //   res =>
    //   {
    //     loading.dismiss();
    //     res.subscribe(c=>
    //       {
    //         this.userProfile = {
    //           cellphone: c.data.cellphone,
    //           dateOfBirth: c.data.dateOfBirth,
    //           email: c.data.email,
    //           firstname: c.data.firstname,
    //           gender: c.data.gender,
    //           id: c.data.id,
    //           lastname: c.data.lastname,
    //           telephone: c.data.telephone,
    //           userId: c.data.userId,
    //           website: c.data.website
    //         };
    //       });
    //   }
    // );
  }
}

Есть ли у кого-нибудь простой пример того, как этого добиться, и мне нужно использовать профиль нагрузки для навигации по приложению, так как в данный момент вошел в систему сможет ли пользователь управлять своим профилем и связанными с ним элементами списка (документами)?

...