I am attempting to get the values of a BehaviorSubject. The values are returned but how to i utilized them to use them in a return true/false statement.
BehaviorSubject {_isScalar: false, observers: Array(0), closed: false, isStopped: false, hasError: false, …}
closed:false
hasError:false
isStopped:false
observers:[Subscriber]
thrownError:null
value:(...)
_isScalar:false
_value:Array(3)
0:"[email protected]"
1:"Bob Smith"
2:{adminUser: false, basicUser: true} length:3
__proto__:Array(0)
__proto__:Subject
My Behavior Subject has the following being sent to it. Why am i getting null at the start.
user: BehaviorSubject<User> = new BehaviorSubject<User>(null);
// The behavior-roles of the user.
this.afAuth.authState
.switchMap(auth => {
if (auth) {
/// signed in
const authData = this.db.list<User>('users/' + auth.uid).valueChanges();
console.log(authData);
return this.db.list<User>('users/' + auth.uid).valueChanges();
} else {
/// not signed in
return Observable.of(null);
}
})
// .subscribe(console.log); // check the subscription
.subscribe((userData) => {
console.log(userData);
this.user.next(userData);
// this.user.next(user);
// console.log(this.user.next(userData));
});
}
The results i am having issues with:
Check Value false authguard.service.ts:39
Route was False authguard.service.ts:26
Check Value true
I run console.log and the value shows up null first therefore has a false response. Then it runs again and becomes true. This all happens after running the page initially. I need for my check value to be true on load.