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

$auth.submitLogin callback don't fire #51

Closed
m2omou opened this issue Oct 18, 2014 · 15 comments
Closed

$auth.submitLogin callback don't fire #51

m2omou opened this issue Oct 18, 2014 · 15 comments

Comments

@m2omou
Copy link

m2omou commented Oct 18, 2014

It works fine with $auth.submitRegistration but not with $auth.submitLogin.

$scope.handleLoginBtnClick = function() {
            $auth.submitLogin($scope.loginForm)
                .then(function(resp) {
                    alert("success");
                })
                .catch(function(resp) {
                   alert("error");
                });
        };

This is what I get in my browser console

TypeError: Cannot read property 'resolve' of null
    at Object.resolveDfd (http://localhost:3000/assets/ng-token-auth.js?body=1:311:23)
    at Object.handleValidAuth (http://localhost:3000/assets/ng-token-auth.js?body=1:464:27)
    at http://localhost:3000/assets/ng-token-auth.js?body=1:179:25
    at http://localhost:3000/assets/angular.js?body=1:8114:11
    at wrappedCallback (http://localhost:3000/assets/angular.js?body=1:11574:81)
    at http://localhost:3000/assets/angular.js?body=1:11660:26
    at Scope.$eval (http://localhost:3000/assets/angular.js?body=1:12703:28)
    at Scope.$digest (http://localhost:3000/assets/angular.js?body=1:12515:31)
    at Scope.$apply (http://localhost:3000/assets/angular.js?body=1:12807:24)
    at done (http://localhost:3000/assets/angular.js?body=1:8380:45) 

I can see that the login works well in the server, here is the rails server logs

Completed 200 OK in 572ms (Views: 2.0ms | ActiveRecord: 14.3ms)
@m2omou m2omou changed the title $auth.submitLogin callback don $auth.submitLogin callback don't fire Oct 18, 2014
@lynndylanhurley
Copy link
Owner

Thanks @m2omou, I'll look into this ASAP.

@jasonswett
Copy link
Contributor

Might be helpful to see your full controller code too.

@m2omou
Copy link
Author

m2omou commented Oct 21, 2014

After many trials It's working fine now, I don't really know what was the problem but it's working.

I put the .run() above the .config() maybe that's the reason... :)

@lynndylanhurley
Copy link
Owner

Cool, thanks @m2omou. I couldn't reproduce this one, but please re-open this issue if the problem recurs.

nbrustein pushed a commit to nbrustein/ng-token-auth that referenced this issue May 27, 2015
@mustela
Copy link

mustela commented Jan 5, 2016

I'm having the same issue here

TypeError: Cannot read property 'resolve' of null
    at Object.resolveDfd (ng-token-auth.js:374)
    at Object.handleValidAuth (ng-token-auth.js:572)
    at ng-token-auth.js:190
    at angular.js:10296
    at processQueue (angular.js:14792)
    at angular.js:14808
    at Scope.$eval (angular.js:16052)
    at Scope.$digest (angular.js:15870)
    at Scope.scopePrototype.$digest (hint.js:1972)
    at Scope.$apply (angular.js:16160)(anonymous function) @ angular.js:12520
angular.js:10765 XHR finished loading: GET "http://app.dev-myapp.io:8090/app/backend/toolbar/layouts/vertical-navigation/toolbar.html".(anonymous function) @ angular.js:10765sendReq @ angular.js:10558serverRequest @ angular.js:10268processQueue @ angular.js:14792(anonymous function) @ angular.js:14808Scope.$eval @ angular.js:16052Scope.$digest @ angular.js:15870scopePrototype.$digest @ hint.js:1972Scope.$apply @ angular.js:16160scopePrototype.$apply @ hint.js:2035(anonymous function) @ angular.js:17927completeOutstandingRequest @ angular.js:5552(anonymous function) @ angular.js:5829

Usually you have to submit twice to log in.

@carlospliego
Copy link

@mustela I am experiencing the same problem. Did you find a solution?

@mustela
Copy link

mustela commented Jan 20, 2016

@carlospliego yes and no :)

I'm using https://github.com/lynndylanhurley/devise_token_auth, so after changing change_headers_on_each_request to false, it did not happen again, so there is def something with how its dealing with the tokens.

Hope that helps

@carlospliego
Copy link

@lynndylanhurley it seems @nbrustein has a commit that references this, not sure if it has fixed anything or if there was a pull request for this.

@marcguilera
Copy link

I'm experiencing the same issue. @mustela @carlospliego @lynndylanhurley did you find any solution? I'm using https://github.com/lynndylanhurley/devise_token_auth as well and setting

config.change_headers_on_each_request = false

In the initializer didn't help.

angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:12521 TypeError: Cannot read property 'resolve' of null at Object.resolveDfd (ng-token-auth-dc177e77451d8a3edd9e0903ea6bbaee.js?body=1:381) at Object.handleValidAuth (ng-token-auth-dc177e77451d8a3edd9e0903ea6bbaee.js?body=1:586) at ng-token-auth-dc177e77451d8a3edd9e0903ea6bbaee.js?body=1:197 at angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:10297 at processQueue (angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:14793) at angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:14809 at Scope.$eval (angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:16053) at Scope.$digest (angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:15871) at Scope.$apply (angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:16161) at done (angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:10590)(anonymous function) @ angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:12521(anonymous function) @ angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:9293processQueue @ angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:14801(anonymous function) @ angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:14809Scope.$eval @ angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:16053Scope.$digest @ angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:15871Scope.$apply @ angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:16161done @ angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:10590completeRequest @ angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:10788requestLoaded @ angular-4fefbb3a1144ecde52b8971452baf5b4.js?body=1:10729

I cleared my controller to debug so all I'm left is with a call to:

$auth.submitLogin({email:'[email protected]',password:'pwd123')

Acording to my rails logs the posts gets to '/api/v1/auth/sign_in' and it gives a 200 back with the info. I've tried with postman and the requests do work.

@mustela
Copy link

mustela commented Jan 28, 2016

@marcguilera as you said, at the beginning I thought that changing config.change_headers_on_each_request = false did work, but it didn't :(

I'm keep looking for answers. Will post as soon as I have something.

@marcguilera
Copy link

Registrations works and the validation event gets triggered giving me the user that I attempted to log in earlier which is weird because it failed apparently. Thanks!

@rubenabergel
Copy link

I had the same issue and solved it. The problem is the way you are calling the function within your controller. Paste it and I ll show you.

@phensalves
Copy link

I have same issue here. Any resolution?

@bendangelo
Copy link

Any resolutions?

@SeraphAdmin
Copy link

SeraphAdmin commented Apr 19, 2017

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.

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

10 participants