ultimatecourses / angular-pro-app-seed

Seed project for Angular Pro final application
112 stars 360 forks source link

uid of previous logged in user is kept when accessing AngularFireDatabase #3

Open lmeijdam opened 6 years ago

lmeijdam commented 6 years ago

Hey Todd!

Awesome job on your course! Still enjoying watching!

It got me motivated to build something similar, where I found a small issue; Whenever I log in, the AuthService has; get user() { return this.af.auth.currentUser; }

But it returns just an Object, After logging into another account, the AuthService (as it is singular) doesn't update this .currentUser property. It keeps track of my previous account.

In MealsService (also singular); meals$: Observable<Meal[]> = this.db.list(meals/${this.uid}`)

get uid() { console.log(this.authService.user.uid) return this.authService.user.uid; // still returns old UID } `

There will be an exception that the newly logged in user is not permitted to access the firebase.db.list.

Suggested solution; In the constructor of the MealsService, listen to the 'authState' object of the AuthService as this returns an Observable. Let me know what you think and if you have a similar issue.