I am facing difficulty inserting an object and adding it to the state of my application.
My task is to create an object with data fetched from firebase.user
and user.getIdTokenResult(true)
.
For instance:
loggedInUser = {
uid: user.uid,
displayName: user.displayName
admin: false,
};
const token = await user.getIdTokenResult (true);
loggedInUser.admin = token.claims.admin;
The approach is quite similar to the one above, but I need to accomplish this utilizing only Rxjs operators in order to encapsulate this object within the state of my application.
@Effect
@Effect()
getUser$: Observable<Action> = this.actions$.pipe(
ofType(auth.AuthActionTypes.GET_USER),
switchMap(() => this.authService.getUser().pipe(
map(user => {
const loggedInUser = {
uid: user.uid,
displayName: user.displayName,
admin: false,
}
// **** I need to invoke user.getIdTokenResult() ******
// and retrieve claims.admin then assign it to loggedInUser object admin.
// authState = {
// uid: user.uid,
// displayName: user.displayName,
// admin: true, // can be true or false
// }
return new auth.Authenticated(loggedInUser);
}),
catchError((err => of(new auth.AuthError(err))))
)
I am still getting accustomed to using reactive programming with Rxjs, hence finding it challenging to merge data from encapsulated Observables.