I am having a few problems with an Angular project im working on.
I decided to use Angular7 with Firebase (AngularFire v5)
In my AuthService
export class AuthService {
private authState: Observable<firebase.User>;
public currentUser: firebase.User;
private profileDoc: AngularFirestoreDocument<Item>;
private profile$: Observable<Item>;
export class AuthService {
private authState: Observable<firebase.User>;
public currentUser: firebase.User;
private profileDoc: AngularFirestoreDocument<Item>;
private profile$: Observable<Item>;
constructor(public afAuth: AngularFireAuth, private afs: AngularFirestore) {
this.authState = this.afAuth.authState;
this.afAuth.authState.subscribe((user: firebase.User) => {
this.currentUser = user;
if(user !== null && user.uid) {
this.profileDoc = this.afs.doc<Item>('users/' + user.uid);
this.profile$ = this.profileDoc.valueChanges();
}
});
}
get profile() : Observable<Item> {
return this.profile$;
}
}
I am trying to get a firestore reference to the users profile when they have logged in, and on the frontend in a component show the firstname and lastname of the user.
But when i try and access the profile to subscribe to it:
this._auth.profile.subscribe((profile) => {
console.log("Profile", profile);
});
It gives me errors.
ERROR TypeError: Cannot read property 'subscribe' of undefined