-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guards with StoreRouterConnectingModule #68
Comments
@csutorasr Just experienced the same thing but finally realized that it obscures angular errors thrown for no providers for guards. The error is because the router store is not serializable due to |
@Kaffiend I have provided the guard. Do you have any idea what should I check? |
I've started removing the router from store and the connecting module to make sure there is no other underlying issue being obscured. If you remove these does it throw anything else or work as intended? In the pre 4.x.x version there was a |
I tried |
Personally i think we should be able to dispatch actions to the store for the router reducer to navigate within. But i havent dug that far into the router yet. Im still playing with feature modules and async store state. |
You could try adding an effect with the effects module for the router error actions dispatched by the router-store and see what you can catch there?? ROUTER_CANCEL and ROUTER_ERROR contain the store state before the navigation. Use the previous state to restore the consistency of the store. |
There is no errors shown. My problem is there aren't any errors at all. If an error showed up it would stop the loop between the states. If it is easier to understand: imagine two effects that are calling each other. ( The problem is the guard and the store does the same, but in a more hidden way. ( I think a solution to this problem can be the use of effects in the router-store. The guards should be called by the handler of the effect not by |
I havent done much with it yet, but I'm inclined to agree that effects are the way to go here. I'll be implement some similar things this evening myself so if i run across anything ill be sure to bring it up. |
looking at your updated code above, you could also create a custom selector for the router state and use that in your evaluation. The fact that your routing to guarded routes, and your not using the router store to handle it is probably why your getting the loop. Guards can return a
|
I tried to do something you told me. If you look at my first code, there My code: Guard: checkLogin(url: string): Observable<boolean> {
this.authService.redirectURL = url;
return this.authService.googleAuthenticated$;
} authService: @Injectable()
export class AuthenticationService {
googleAuthenticated$: Store<boolean>;
// ...
constructor(private store: Store<AppStore>) {
this.googleAuthenticated$ = this.store.select(state => state.core.authentication.googleAuthenticated);
// ...
}
// ...
} Probably the observable is fetched instantly (sync) and behaves as a boolean value. |
You will probably still need the effects, or you can try creating a slice of state for ui and dispatch to that reducer from the guard to handle the routing. I have the same need so when i figure it out ill let you know. |
This seems to work without any effects.
root reducer
auth.guard.ts
is this in the same guard?
@csutorasr This is probably where your loop is coming from. How are you providing these guards functions in the module? |
Have you tried to load a guarded page with the In my case I tried with this code which is very similar to yours. checkLogin(url: string): Observable<boolean> {
return this.store.select(s => s.core.authentication)
.map(s => s.googleAuthenticated || s.facebookAuthenticated)
.map(isLoggedIn => {
if (isLoggedIn) {
return true;
}
this.router.navigateByUrl('/');
// this.authService.redirectURL = url; <= i'd like to have this line of code, but first it is nice without it.
return false;
})
} |
can you push up a repo to github so i can look at it? |
I made a repo for the error. I hope it will help you. Tests won't run as I didn't care about them for this example. |
I updated the repo as you said. Nothing have changed. Pull and try that code as I wrote in the description. |
You need to add the operator.
…On Jul 12, 2017 11:02 AM, "Robin Csutorás" ***@***.***> wrote:
I updated the repo as you said. Nothing have changed.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#68 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AHdrNRGuNPaCrnnT3r6VSfBEOFRObnRlks5sNOAAgaJpZM4OUIxf>
.
|
I added the operator, it have pushed it to the master, still not working.
Have you tried the code?
I have no experiences with pull requests, but you can make one if you would
like to. (I hope I will be able to accept it)
|
i've tried and i am getting the same result, but this one is beyond me..i've checked and tried everything i can think of. |
…ith routerReducer Closes ngrx#68
…le when used with routerReducer Closes #68
For the other problem (router redirection to the same page after login) I have a solution with an effect, where SetRedirectURLAction is setting the redirect url after login.
Each time a guard cannot resolve the link, the url is saved. |
any updates on this one? i'm using the current version and it has issues with guards as well |
Bug, feature request, or proposal:
BUG
What is the expected behavior?
Not to loop forever.
What is the current behavior?
If I use a guard for authenticated routes with StoreRouterConnectingModule it gets stuck.
My code for easier understanding:
This guard checks if the users is logged in. The
this.authService.isLoggedIn
gets data from the state of the store. Thethis.authService.redirectURL
dispatches an event to set theredirectURL
in the store. Than the redirects to/login
which is not have this guard. The routing from the router action (maybe changing state during another state change) causes the app stuck.If I remove the
StoreRouterConnectingModule
from the app module everything works as guards and navigate and not handled by the ngrx.What are the steps to reproduce?
Redirect from a guard with activated
StoreRouterConnectingModule
. I made a repo for the bug.Which versions of Angular, NGRX, OS, TypeScript, CLI, browsers are affected?
Newest nightly with angular 4.2.6.
The text was updated successfully, but these errors were encountered: