diff --git a/src/app/services/user/user.service.ts b/src/app/services/user/user.service.ts index 9f0d79a..39d84f8 100644 --- a/src/app/services/user/user.service.ts +++ b/src/app/services/user/user.service.ts @@ -23,6 +23,8 @@ export class UserService { switchMap(uid => this.readUser$(uid)) ) .subscribe(_ => this.iUser$.next(_)); + + this.db.col$('users/').subscribe(_ => this.users$.next(_)); } public get userId$(): Observable { @@ -35,8 +37,9 @@ export class UserService { public currentUser = async (): Promise => firstValueFrom(this.user$); + private users$ = new BehaviorSubject([]); public getUserbyId = (userId: string): Promise => firstValueFrom(this.getUserbyId$(userId)); - public getUserbyId$ = (userId: string): Observable => this.db.doc$('users/' + userId); + public getUserbyId$ = (userId: string): Observable => this.users$.pipe(map(_ => _.find(f => f.id === userId) || null)); public async login(user: string, password: string): Promise { const aUser = await this.afAuth.signInWithEmailAndPassword(user, password); @@ -44,6 +47,7 @@ export class UserService { const dUser = await this.readUser(aUser.user.uid); this.iUser$.next(dUser); this.iUserId$.next(aUser.user.uid); + return aUser.user.uid; }