ng-token-auth icon indicating copy to clipboard operation
ng-token-auth copied to clipboard

signup and signout promises not successfully resolving

Open sachinkaria opened this issue 8 years ago • 5 comments

I have managed to set up ng-token-auth to work with rails devise-token-auth. However when I try to sign up and then login the promise doesn't resolve even though the user is successfully created in the rails database. If the sign up promise resolves the user should automatically be logged in however it never executes this.

Here is my controller:

comeDineApp.controller('userController', ['ipCookie','$scope', '$state', '$auth',
  function(ipCookie, $scope, $state, $auth){

    $scope.handleRegBtnClick = function() {
      $auth.submitRegistration($scope.registrationForm)
        .then(function() {
          $auth.submitLogin({
            email: $scope.registrationForm.email,
            password: $scope.registrationForm.password
          });
        });
    };
}]);

In this case submitLogin function is never executed even though a user is successfully created. Here is the rails feedback I get when creating a user:

Started POST "/auth" for ::1 at 2016-05-31 10:44:35 +0100
Processing by DeviseTokenAuth::RegistrationsController#create as HTML
  Parameters: {"email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "confirm_success_url"=>"http://localhost:8100/#/user/sign_up", "config_name"=>"default", "registration"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "confirm_success_url"=>"http://localhost:8100/#/user/sign_up", "config_name"=>"default"}}
Unpermitted parameters: confirm_success_url, config_name, registration
Unpermitted parameters: confirm_success_url, config_name, registration
Unpermitted parameters: confirm_success_url, config_name, registration
   (0.2ms)  BEGIN
   (0.3ms)  SELECT COUNT(*) FROM "users" WHERE "users"."provider" = $1 AND "users"."email" = $2  [["provider", "email"], ["email", "[email protected]"]]
  SQL (0.4ms)  INSERT INTO "users" ("email", "encrypted_password", "tokens", "uid", "confirmed_at", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING "id"  [["email", "[email protected]"], ["encrypted_password", "$2a$10$SwIccp70rj7Fkhr/mmbzzO0iWZ25zoWmZHhd.Ss.U7EiHY3HDKg5a"], ["tokens", "{}"], ["uid", "[email protected]"], ["confirmed_at", "2016-05-31 09:44:35.290653"], ["created_at", "2016-05-31 09:44:35.290790"], ["updated_at", "2016-05-31 09:44:35.290790"]]
   (0.6ms)  COMMIT
   (0.2ms)  BEGIN
  SQL (0.4ms)  UPDATE "users" SET "tokens" = $1, "uid" = $2, "confirmed_at" = $3, "updated_at" = $4 WHERE "users"."id" = $5  [["tokens", "{\"l8gjteNazg85SmNVb98GDg\":{\"token\":\"$2a$10$ZFFMheopZltbe3aLZKEQy./GKqoDzXuWrLlVxZaNCdLd0z78hAZqG\",\"expiry\":1465897475}}"], ["uid", "e85f6997-4499-49c5-b4b3-16a6d182f1ee"], ["confirmed_at", "2016-05-31 09:44:35.378804"], ["updated_at", "2016-05-31 09:44:35.379174"], ["id", 12]]
   (0.5ms)  COMMIT
Completed 200 OK in 330ms (Views: 0.3ms | ActiveRecord: 2.5ms)

If I manually redirect to the login page I can successfully login. This problem is also happening when I try signOut. The user successfully signs out of the rails API however the promise is not resolved in Angular and the page doesn't redirect.

sachinkaria avatar May 31 '16 10:05 sachinkaria

This works perfectly with signing IN.

sachinkaria avatar May 31 '16 10:05 sachinkaria

Not sure if this is related but I had something similar, where after registration the login event was not emitted. Therefore I broadcast this event myself:

$rootScope.$on('auth:registration-email-success', function(event, user) {
  $log.debug('event auth:registration-email-success: ' + user.email);
  $rootScope.$broadcast('auth:login-success',user);
});

Then I use events to do the state change:

$rootScope.$on('auth:login-success', function(event, user) {
  $log.debug('event auth:login-success');
  // ensure $rootScope contains user object
  $auth.validateUser().then(function(resp) {
    $state.go('some_state');
  });
});

abhayastudios avatar Jun 06 '16 15:06 abhayastudios

+1 I have this issue with gem 'devise_token_auth' on my backend server

poc7667 avatar Jun 27 '16 18:06 poc7667

@abhayastudios In which part of your code did you do this? I think I have the same issue as my use is logged in but I can't go to another state. Although my app is in HTML and Java. But that is not important, I guess. I tried using those events but I think I am putting them in the wrong place in my code as they do not resolve my issue...

pierrettemugisha avatar Jul 14 '16 17:07 pierrettemugisha

I haven't found a solution to this issue yet, the promises still don't resolve for sign-up and sign-out

sachinkaria avatar Aug 16 '16 14:08 sachinkaria