Skip to content

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

Description

@lmeijdam

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<fb.user>. Let me know what you think and if you have a similar issue.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions