lynndylanhurley / ng-token-auth

Token based authentication module for angular.js.
Do What The F*ck You Want To Public License
1.8k stars 234 forks source link

$auth.submitLogin doesn't call back #270

Open Mikodin opened 8 years ago

Mikodin commented 8 years ago

I noticed that this was a problem back in 2014, #51 and I am having the exact same error. It seems there was no "fix" and maybe it just got patched over or something, but it's popping up for me. I am not doing anything crazy, pretty much what the example is, using the same kind of form.

I am dreadfully sorry for not using code but it is formatting all of this horridly

Here is the error angular.js:13236 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:10973 at angular.js:15552 at m.$eval (angular.js:16820) at m.$digest (angular.js:16636) at m.$apply (angular.js:16928) at g (angular.js:11266) at t (angular.js:11464)

Here is my controller

theApp.controller('loginCtrl', function($scope,$auth) { $scope.handleLoginBtnClick = function() { $auth.submitLogin($scope.loginForm) .then(function(resp) { console.log("Logged in!?"); // handle success response }) .catch(function(resp) { console.log($scope.loginForm); console.log("Obviously got an error response!"); $scope.loginErrorMessage = "Sorry, but uh we couldn't find you, try again"; // handle error response }); }; });

And finally, my view is exactly what you have in your example, just a form.

Any help would be glorious :), I've been hacking around with it for about 2 hours and I'm just spinning my tires at this point.

Thank you!

gerardvcruz commented 8 years ago

+1 for this, I've been getting this error constantly. Cannot resolve the login even if it's successful. It has something to do with the deferred promise somehow becoming null. I think there's something wrong with @initDfd() in submitLogin

  1. @initDfd() is called in submitLogin, something goes wrong with the initialization, @dfd is set to null
  2. handleValidAuth is called
  3. @resolveDfd is called within handleValidAuth, but @dfd is null so it throws an error

Not 100% sure if this is the problem but I've tried tracing it as much as I can @lynndylanhurley any help would be much appreciated

merqlove commented 8 years ago

@gerardvcruz @Rayne58 Hmm, have not seen this bug before. It's happen after login via email/pass? Maybe it is timeout?

src/ng-token-auth.coffee#L419

charlesdg commented 8 years ago

We don't have an error but we have this asynchronous problem with omniauth authentication. The @dfd is set to null then the promise is never resolved.

carsonmcdonald commented 8 years ago

I ran into this same issue and for me it was the validateOnPageLoad setting. I was calling submitLogin as soon as the page loaded for testing reasons. After a little debugging of what could set @dfd to null I noticed that when validateOnPageLoad is true (the default) it calls validateUser on page load. So if you call anything else that uses @dfd on page load there is a good chance you are going to clobbered by that call to validateUser. The easy fix was to set validateOnPageLoad to false.

rubenabergel commented 8 years ago

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.

dmitry-a-l commented 8 years ago

@rubenabergel Hey, I have the same issue. But I use sumbitLogin directly in form

form ng-submit="submitLogin(loginForm)" role="form" ng-init="loginForm = {}"
  .form-group
    label for="email" Email
    input id="email" ng-model="loginForm.email"
  .form-group
    label for="password" Password
    input type="password" id="password" ng-model="loginForm.password"
  .buttons-row
    button.btn.btn-primary type="submit" Log In

What is the correct way to call submitLogin for me?

abhayastudios commented 8 years ago

see how I handle this here by using events.