This commit is contained in:
2020-03-02 18:47:04 +01:00
committed by smuddy
parent 5b746e0db5
commit ccd91aa81c
93 changed files with 444 additions and 89 deletions

View File

@@ -0,0 +1,12 @@
import {TestBed} from '@angular/core/testing';
import {UserService} from './user.service';
describe('UserService', () => {
beforeEach(() => TestBed.configureTestingModule({}));
it('should be created', () => {
const service: UserService = TestBed.get(UserService);
expect(service).toBeTruthy();
});
});

View File

@@ -0,0 +1,21 @@
import {Injectable} from '@angular/core';
import {AngularFireAuth} from '@angular/fire/auth';
import {Observable} from 'rxjs';
import {filter, switchMap} from 'rxjs/operators';
import {User} from './user';
import {AngularFirestore} from '@angular/fire/firestore';
@Injectable({
providedIn: 'root'
})
export class UserService {
constructor(private afAuth: AngularFireAuth, private afs: AngularFirestore) {
}
public get user$(): Observable<User> {
return this.afAuth.authState.pipe(
filter(_ => !!_),
switchMap(auth => this.afs.doc<User>('user/' + auth.uid).valueChanges())
);
}
}

4
src/app/services/user.ts Normal file
View File

@@ -0,0 +1,4 @@
export interface User {
name: string;
role: 'admin';
}