ng-token-auth
ng-token-auth copied to clipboard
"Cannot read property 'resolve' of null" on $auth.validateToken() and "user_signed_in?" always false
Application code This error is related to this and this
My actions:
-
$auth.submitLogin({email: "[email protected]", password: "melgaardbjorn"})
All fine,userIsAuthenticated = true
but on refreshp #{user_signed_in?}
is false and all api actions, which triggerbefore_action :authenticate_user!
dont process, example:
# console
PollResource.save({title: "poll2"})
# log
Started POST "/api/polls" for ::1 at 2016-06-05 11:37:16 +0300
Processing by PollsController#create as JSON
Parameters: {"title"=>"poll2", "poll"=>{"title"=>"poll2"}}
Filter chain halted as :authenticate_user! rendered or redirected
Completed 401 Unauthorized in 2ms (Views: 0.3ms | ActiveRecord: 0.0ms)
-
$auth.validateToken()
return successful promise, but trigger
# on chrome console
TypeError: Cannot read property 'resolve' of null
at Object.resolveDfd (ng-token-auth.self-8a84fb0….js?body=1:334)
at Object.handleValidAuth (ng-token-auth.self-8a84fb0….js?body=1:531)
at ng-token-auth.self-8a84fb0….js?body=1:444
at angular.self-a3680ff….js?body=1:11321
at processQueue (angular.self-a3680ff….js?body=1:16105)
at angular.self-a3680ff….js?body=1:16121
at Scope.$eval (angular.self-a3680ff….js?body=1:17379)
at Scope.$digest (angular.self-a3680ff….js?body=1:17192)
at Scope.scopePrototype.$digest (hint.js:1364)
at Scope.$apply (angular.self-a3680ff….js?body=1:17487)
# log
Started GET "/api/auth/validate_token" for ::1 at 2016-06-05 11:41:02 +0300
Processing by DeviseTokenAuth::TokenValidationsController#validate_token as JSON
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."uid" = ? LIMIT 1 [["uid", "[email protected]"]]
(0.1ms) begin transaction
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 3]]
SQL (0.2ms) UPDATE "users" SET "tokens" = ?, "updated_at" = ? WHERE "users"."id" = ? [["tokens", "{\"t3nZlr0E895VfQ0nLGhAXw\":{\"token\":\"$2a$10$VRIF.UK.sIDoI3lB5MeliuJcHQ0.DxTQLPea0V0cmgLrB0S1gUvw6\",\"expiry\":1466321224,\"last_token\":\"$2a$10$NWqSoAycEppP4EUfOCv.COSdC2vsb9dbosOG7BNzatXFBXtz34/d2\",\"updated_at\":\"2016-06-05T10:27:04.343+03:00\"},\"OEwI8gbTj8TEolR7n_jjzg\":{\"token\":\"$2a$10$IcY7IVEWcdr2qylHHLGa/.KaGc6wCcOxmTD5bdz/MMZNact7n/sye\",\"expiry\":1466321700,\"last_token\":\"$2a$10$cP0M9OCBNKec7J2OipAvl.orOIA7/3qCeplqilkDEnciVdptPa54W\",\"updated_at\":\"2016-06-05T10:35:00.660+03:00\"},\"rkBYjwN2ilEVzfrh3FKO7w\":{\"token\":\"$2a$10$KILfgu.8Tffz/CRrh17xZ.EaT1q4hWiZPKqdC/PdRqWNCtb9XNwMi\",\"expiry\":1466325662,\"last_token\":\"$2a$10$8PVVcuhB1S4iCYS2YHaS1ez75NRZwDtSm8P5/LpW.a5bpOZreqjdW\",\"updated_at\":\"2016-06-05T11:41:02.688+03:00\"}}"], ["updated_at", "2016-06-05 08:41:02.689389"], ["id", 3]]
(4.0ms) commit transaction
Completed 200 OK in 176ms (Views: 0.3ms | ActiveRecord: 4.6ms)
On rails 5.0.0.rc1 situation is the same
- devise (4.0.3)
- devise_token_auth (0.1.37)
I'm having the same issue. On signout it even complains that there's no user to sign out.
@TBurk83 , i forsake the idea of using this gem and moved to angular-devise, if you need token authentication, try tiddle
@BjornMelgaard Would that approach work even if my Angular client was living on a different server than my Rails API? I haven't kept up with the core Devise gem in a while.
@TBurk83 , maybe this will help
@BjornMelgaard Yeah, already using rack-cors. Thanks, though!
The angular-devise method you mentioned seems promising. I was just wondering if there were any drawbacks to using it versus token-based authentication. Personally, I am done trying to get this gem and module to work after a very frustrating day and a half.
I was trying to get this gem to work about a month. I questioned this too, but didnt find anything, If you find out, let me know, thanks)
The issue seems to be fixed by 888f251157e1d24ce35e6f466e6ff5a22c31bd36 which wasn't released yet, you can easily test it:
bower install https://github.com/lynndylanhurley/ng-token-auth.git#master
@booleanbetrayal @lynndylanhurley Could you tag a new release, please?
It was by no means fixed , it won't trigger the error but it won't do anything also it just returns if there is no dfd which it won't ever be.
this.initDfd();
debugger;
$http.post(this.apiUrl(opts.config) + this.getConfig(opts.config).emailSignInPath, params, httpopts).success((function(_this) {
return function(resp) {
debugger;
var authData;
_this.setConfigName(opts.config);
authData = _this.getConfig(opts.config).handleLoginResponse(resp, _this);
_this.handleValidAuth(authData);
return $rootScope.$broadcast('auth:login-success', _this.user);
};
dfd is initialized wih $q.defer();
and all if fine. then this gets called _this.handleValidAuth(authData);
. Here _this.dfd is null even though $q.defer()
remains a promise. In that function this.resolveDfd()
gets called but since this is actually _this and _this.dfd was null this.dfd will also be null
. Please fix this :)