Skip to content

Commit cf0fd09

Browse files
author
Your Name
committed
Firebase & AngularFire In Depth
1 parent 90a892c commit cf0fd09

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/app/services/user.service.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {Observable} from "rxjs";
33
import {AngularFireAuth} from "@angular/fire/auth";
44
import {map} from "rxjs/operators";
55
import {Router} from "@angular/router";
6+
import {UserRoles} from "../model/user-roles";
67

78

89
@Injectable({
@@ -16,6 +17,8 @@ export class UserService {
1617

1718
pictureUrl$: Observable<string>;
1819

20+
roles$ : Observable<UserRoles>;
21+
1922
constructor(
2023
private afAuth: AngularFireAuth,
2124
private router: Router) {
@@ -27,6 +30,11 @@ export class UserService {
2730
this.pictureUrl$ =
2831
afAuth.authState.pipe(map(user => user? user.photoURL : null));
2932

33+
this.roles$ = this.afAuth.idTokenResult
34+
.pipe(
35+
map(token => <any>token?.claims ?? {admin:false})
36+
)
37+
3038
}
3139

3240

0 commit comments

Comments
 (0)