Issue
this is my Realtime database I want to find the article of the person connected and display infomation
This is my ionic script page
here are my imports I can retrieve the id of the user to connect but I cannot retrieve this information in the real time database
import { Component } from '@angular/core';
import { AngularFireAuth } from '@angular/fire/compat/auth';
import { AngularFireDatabase, AngularFireList } from '@angular/fire/compat/database';
export class Tab3Page {
public profileData: any;
name: string;
prenom: string;
constructor(private afAuth: AngularFireAuth,
private db: AngularFireDatabase,
private toast: ToastController,
private navCtrl: NavController,
private authService: FirebaseAuthServiceService) {
this.afAuth.authState.subscribe(
(res)=>{
this.profileData = res.uid;
console.log(this.profileData);
}
)
this.db.list("users/"+this.profileData).valueChanges().subscribe(details => {
this.name =details["name"];
this.prenom = details["prenom"];
console.log(details);
})
}
}
Solution
It's hard to be certain, but I have a feeling you are attaching the database listener before the user is signed in. To fix that you need to move the subscribe call into the auth state listener"
this.afAuth.authState.subscribe(
(res)=>{
this.profileData = res.uid;
console.log(this.profileData);
}
this.db.list("users/"+this.profileData).valueChanges().subscribe(details => {
this.name =details["name"];
this.prenom = details["prenom"];
console.log(details);
})
)
If this indeed gets the data loaded you'll want to start managing the database subscription, as the authState
may of course change over time.
Answered By - Frank van Puffelen
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.