I've got this route guard which should check the user's role as well as a roleAccess property defined in the route definition.
The problem I'm facing is that .map executes regardless of accounts.isSelfPending, only when that is false (it starts off as null in the @ngrx/store) should it allow .map to run.
How can I achieve this?
EDIT: I realise that my question could be a bit vague, what I need is to wait for the user's information from a /self request that is fired higher up the the component hierarchy, and stored in the store.
The problem now is that the /self request isn't even being fired despite being fired in my DashboardComponent, which in turn holds the AdsComponent as one of it's children in the routing. (Which is the route I'm currently trying to lock with this guard).
Why isn't it even firing the /self request? Which I assume is part of this problem.
return this.store.select('accounts')
.let((state: Observable<IAccountsStorage>) => state.filter((accounts: IAccountsStorage) => accounts.isSelfPending !== null && accounts.isSelfPending === false)))
.map((accounts: IAccountsStorage) => {
this.route.data.subscribe(
data => {
if (accounts.self) {
if (accounts.self.role !== data['roleAccess'] && (data['roleAccess'] !== 0 || data['roleAccess'] !== undefined || data['roleAccess'] !== null)) {
return this.router.navigateByUrl('admin/dashboard');
}
else {
return true;
}
}
}
);
}
).first();
After realising that using the store as the middle man was causing too much problems I decided to just call the api directly, ending up with a much clearer guard that actually works as intended.
I figured that this might help someone else so I'll leave the final solution here:
However, if someone knows how to solve the question with the original code please provide it as I'm curious how to actually do it using the store.