Skip to content
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

Infinite $stateChangeStart event loop #32

Closed
cojack opened this issue Dec 27, 2014 · 1 comment
Closed

Infinite $stateChangeStart event loop #32

cojack opened this issue Dec 27, 2014 · 1 comment

Comments

@cojack
Copy link

cojack commented Dec 27, 2014

Hello,
I figure out new problem an infinite loop. When it happen?

Let's say that we have some abstract state app with default permissions for rest of the states

$stateProvider.state('app', {
            abstract: true,
            data: {
                permissions: {
                    only: ['user'],
                    redirectTo: 'auth.login'
                }
            }
});

Then create some state fe: app.start

$stateProvider
            .state('app.start', {
                url: '/start',
                views: {
                    'some@app': {
                        // ble ble ble
                    }
                },
                data: {
                    title: 'Start'
                }
            });

It inherit perms from state app

Then, we need an authorization for our app, so create an auth state with state auth.login

$stateProvider.state('auth', {
            abstract: true,
            data: {
                permissions: {
                    except: ['user'],
                    redirectTo: 'app.start'
                }
            },
            views: {
                // bla bla bla
            }
        }).state('auth.login', {
            url: '/login',
            views: {
                // bla bla bla
            },
            data: {
                title: 'Login',
                htmlId: 'extr-page'
            }
        });

After this when you point your web browser to the root of the app fe: localhost:1337 they will do an infinite event loop, from state app.start to auth.login and back.

How looks a defineRole of the user?:

Permission.defineRole('user', function() {
            return user.checkSession();
        });

where user is an service with checkSession function that returns promise.

I just debug it, and it looks like it check that user (not logged, anonymous) have an permissions to app.start and he doesn't have of course, then is called state.go (because redirectTo is set up) to auth.login, an event is fired once again (due to my changes in #30 ) and then there are checked perms once again for state auth.login user is not authorizated, but permissions for auth.login is except user, so checkSession returns false, and process of Permission.authorize goes it returns resolve promise, but after this event is fired once again (have no idea why, maybe it's a bug in angular-ui-route [my version is: v0.2.11]). I have also check it on stock version of your code, and it happens exactly the same way.

Anyway, an fix is a remove event.preventDefault() from an your module, I will provide an pull request.

@RafaelVidaurre
Copy link
Owner

This error has to do with a bug coming from ui-router and it was fixed on a previous PR (which you reverted in #31)

So the line with the "notify: false" snipped you deleted created this error. Let me know if anything pops up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants