From ae4ec8c997efa75918e81a3b3be92f19f635efdb Mon Sep 17 00:00:00 2001 From: salah3x Date: Fri, 26 Jul 2019 22:12:01 +0100 Subject: [PATCH] Fix #20 --- src/app/shared/store.service.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/app/shared/store.service.ts b/src/app/shared/store.service.ts index 04c241b..1844a81 100644 --- a/src/app/shared/store.service.ts +++ b/src/app/shared/store.service.ts @@ -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'; @@ -22,7 +22,21 @@ export class StoreService { getUser(): Observable { return this.authService.user.pipe( switchMap(user => - user ? this.db.doc(`users/${user.uid}`).valueChanges() : of(null) + user + ? this.db + .doc(`users/${user.uid}`) + .valueChanges() + .pipe( + tap(u => { + if (!u.name) { + this.db.doc(`users/${u.id}`).update({ + name: user.displayName, + name_lowercase: user.displayName.toLowerCase() + }); + } + }) + ) + : of(null) ) ); }