login
This commit is contained in:
12
src/app/services/user.service.spec.ts
Normal file
12
src/app/services/user.service.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
21
src/app/services/user.service.ts
Normal file
21
src/app/services/user.service.ts
Normal 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
4
src/app/services/user.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface User {
|
||||
name: string;
|
||||
role: 'admin';
|
||||
}
|
||||
Reference in New Issue
Block a user