-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Multiple users, returning(and creating) wrong model's auth token #399
Comments
After further looking into the issue. module A1
class ShopsController < ApplicationController
before_action :authenticate_employee!, only: [:index, :show, :update]
def index
puts current_user.to_json
puts current_employee.to_json
@shops = current_employee.shops.select(:id, :name)
render json: @shops, root: 'data', each_serializer: A1::ShopListSerializer
end current_user shouldn't exist but... it is printing out id of current_employee. When running the Index method, set_user_by_token gets called twice. def set_user_by_token
rc = resource_class(mapping) First rc returns "Employee" and Second rc returns "User" render json: {}, root: 'data', each_serializer: A1::ShopListSerializer returning {} json only triggers set_user_by_token once. |
more.. detail From: /Users/daniel/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/action_controller/metal/instrumentation.rb @ line 43 ActionController::Instrumentation#render:
41: def render(*args)
42: render_output = nil
=> 43: self.view_runtime = cleanup_view_runtime do
44: Benchmark.ms { render_output = super }
45: end
46: render_output
47: end
[1] pry(#<A1::ShopsController>)> next
User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
(0.5ms) BEGIN
SQL (0.9ms) UPDATE "users" SET "tokens" = $1, "updated_at" = $2 WHERE "users"."id" = $3 If I go more in depth From: /Users/daniel/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/actionpack-4.2.3/lib/abstract_controller/rendering.rb @ line 25 AbstractController::Rendering#render:
23: def render(*args, &block)
24: options = _normalize_render(*args, &block)
=> 25: self.response_body = render_to_body(options)
26: _process_format(rendered_format, options) if rendered_format
27: self.response_body
28: end
[1] pry(#<A1::ShopsController>)> next
User Load (1.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT 1 [["id", 1]]
(0.5ms) BEGIN
SQL (1.0ms) UPDATE "users" SET "tokens" = $1, that is where users's token is being updated... |
I have created new app from scratch, and it seems to work fine.... |
@danielchoi I am facing a similar issue, not with two different models but sometimes the tokens on response its from another user than I set on the request. Did you find something to help? |
I have two models called 'User' and 'Worker' and I am using devise_token_auth only for 'Worker' but rc in @danielchoi @pedroviana |
@noopurj |
Client side is using ng-token-auth.
I have "User" and "Employee" model.
Login to Employee model returns correct auth_token(valid).
Any calls that I make after that against methods using "before_action :authenticate_employee!"
creates new auth token for "User" and returns it in response header, thus updating my client(supposed to be employee with User model's auth token info)
I have narrowed down the issue to "set_user_by_token" which creates new auth token, and "update_auth_header" which response with wrong credential in the header.
both rc and devise_warden_user returns "User" when it print them out.
Here is my route... incase I am doing something wrong. My API is calling agains "a1/shops#index"
I will be keep digging but any help would be nice.
Thanks.
The text was updated successfully, but these errors were encountered: