ng-token-auth
ng-token-auth copied to clipboard
Deferred promise not resolving - $auth.validateUser() in Ionic ui-router
Hi, I use $auth.validateUser() in ui-router resolve. When I want to change the state after login most times promise returned by $auth.validateUser() does not resolve.
Situation occurs every time that this.dfd object is already created when validateUser() function is executed.
validateUser: function(opts) {
var clientId, configName, expiry, location_parse, params, search, token, uid, url;
if (opts == null) {
opts = {};
}
configName = opts.config;
console.log(this.dfd);
if (this.dfd == null) {
Is it safe to set this.dfd to null at the start of validateUser function to workaround the problem?
BTW, there is no such problem with web version of the app.
I am also experiencing the same problem. Did setting this.dfd to null work for you? Are you using master branch or the 0.0.29 release?
Just a note, I'm using the web version and it is not resolving correctly.
Oh nevermind, it's working now. That was a slight misunderstanding on my part.
@mrsweaters Unfortunatelly setting this.dfd to null breaks other things... I've discovered that if one changes state after some time (using setTimeout function for example), the promise successfully resolves, so there must be some time of race condition. I hadn't more time to investigate further..
I've also encountered that bug:(
I figured out at least one reason why this occurs. My error was that I was simultaneously calling submitLogin in a controller method on an ng-click of the submit button AND had the submitLogin() in the ng-submit of the form definition. This caused the submit to occur twice in rapid succession. Apparently the ng-click gets handled first which means the promise handed back from submitLogin is from the ng-click. Since the deferred is a global within ng-token-auth the first one gets clobbered when the second one (the one from the ng-submit) occurs and only the second one is resolved.
Check your network log and see if you happen to be submitting two auth requests in rapid succession for some reason. That could be where the root of the problem for some people.