Skip to content

Commit

Permalink
Fix #20
Browse files Browse the repository at this point in the history
  • Loading branch information
salah3x committed Jul 26, 2019
1 parent 527680b commit ae4ec8c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/app/shared/store.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AngularFireAuth } from '@angular/fire/auth';
import { AngularFirestore } from '@angular/fire/firestore';
import { firestore } from 'firebase/app';
import { combineLatest, of, Observable, throwError } from 'rxjs';
import { switchMap, map, take, catchError } from 'rxjs/operators';
import { switchMap, map, take, catchError, tap } from 'rxjs/operators';

import { User, Friendship, Request } from './models';
import { environment } from '../../environments/environment';
Expand All @@ -22,7 +22,21 @@ export class StoreService {
getUser(): Observable<User> {
return this.authService.user.pipe(
switchMap(user =>
user ? this.db.doc<User>(`users/${user.uid}`).valueChanges() : of(null)
user
? this.db
.doc<User>(`users/${user.uid}`)
.valueChanges()
.pipe(
tap(u => {
if (!u.name) {
this.db.doc<User>(`users/${u.id}`).update({
name: user.displayName,
name_lowercase: user.displayName.toLowerCase()
});
}
})
)
: of(null)
)
);
}
Expand Down

0 comments on commit ae4ec8c

Please sign in to comment.