stormpath / stormpath-sdk-angularjs

User Management for AngularJS (1.x) applications
http://docs.stormpath.com/angularjs/sdk/
Apache License 2.0
165 stars 58 forks source link

Dependency issue when using UI-Router 0.3 #202

Open robertjd opened 7 years ago

robertjd commented 7 years ago

Upgrading UI-Router to 0.3 causes this exception in our code, if UI-Router is listed before stormpath in the module dependencies:

angular.js:4442 Uncaught Error: Unrecognised token store: localStorage
    at Object.getTokenStore (stormpath-sdk-angularjs.js:3394)
    at new StormpathOAuthToken (stormpath-sdk-angularjs.js:2322)
    at StormpathOAuthTokenProvider.$get (stormpath-sdk-angularjs.js:2476)
    at Object.invoke (angular.js:4478)
    at angular.js:4295
    at getService (angular.js:4437)
    at Object.invoke (angular.js:4469)
    at Object.enforcedReturnValue [as $get] (angular.js:4330)
    at Object.invoke (angular.js:4478)
    at angular.js:4295

Reproduction in the head of this branch:

https://github.com/stormpath/express-stormpath-angular-sample-project/commit/66f5ed20111bf92b547feb634fcbec34e3dc45e5

oldskool73 commented 7 years ago

I just found this service today, and immediately hit this same issue running through the intro guide.

Moving the UI Router below the Stormpath entries in the App DI array (as per your comment in the link above) does NOT fix it for me, it actually has to be moved to the VERY TOP of the array, above any and all other modules.

It also didn't work when downgrading to UI-Router 0.2.8, exactly the same issue, so perhaps it's not an issue with UI-Router 0.3 at all, but with your code somewhere else?

the-overengineer commented 7 years ago

I suspect it was an error due to the order .run blocks were being executed. Since .config is not an option due to using $q, I just made the the token store initialisation lazy, so it runs when needed, not when the StormpathOAuth service is created. No longer getting the issue after that.

mgruel commented 7 years ago

Is there a timeline, when this fix will be available?

kevinch commented 7 years ago

Issue confirmed even on ui-router 0.4.2 and angular 1.6.1 with only ui-router, stormpath and stormpath.templatesas dependencies.

mikeymco commented 7 years ago

Moving 'ui-router' to a position after 'stormpath' in my module DI array resolved this issue for me. (Angular 1.6.2, ui-router 1.0.0-rc.1)