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

Unable to sign_out a user that is being deleted which causes 404 as devise_token_auth attempts to find to create headers. #1205

Closed
lassiter opened this issue Aug 23, 2018 · 1 comment

Comments

@lassiter
Copy link

I'm expecting on delete to get a 204 but get a 404 because devise_token_auth attempts to find to create headers:

devise_token_auth (0.2.0) app/controllers/devise_token_auth/concerns/set_user_by_token.rb:122:in `block in update_auth_header'
devise_token_auth (0.2.0) app/controllers/devise_token_auth/concerns/set_user_by_token.rb:32:in `ensure_pristine_resource'
devise_token_auth (0.2.0) app/controllers/devise_token_auth/concerns/set_user_by_token.rb:119:in `update_auth_header'

This stack overflow question was posted earlier before I realized that devise_token_auth was searching for member to create new headers because the current_user had not been signed out. I tried doing sign_out current_user which returned an empty hash but still returned the same 404 error. Am I missing something?

This is my member controller:

  def destroy
    begin
      @member = Member.find(member_params[:id])
      authorize @member
      @member.destroy
      render json: {}, status: :no_content
    rescue Pundit::NotAuthorizedError
      @member.errors.add(:id, :forbidden, message: "current user is not authorized to delete member id: #{params[:id]}")
      render :json => { errors: @member.errors.full_messages }, :status => :forbidden
    rescue ActiveRecord::RecordNotFound
      render :json => {}, :status => :not_found
    end
  end

  def member_params
    params.require(:member).permit(:id, :attributes =>[:avatar, :name, :surname, :nickname, :gender, :bio, :birthday, :instagram, :email, :addresses => [:type, "line-1", "line-2", :city, :state, :postal], :contacts => [:home, :work, :cell] ])
  end
  • Version: which version of this gem (and [ng-token-auth]
    Latest gem version

  • SQL Log Right before Stacktrace:

Started DELETE "/v1/members/3" for 127.0.0.1 at 2018-08-22 20:20:39 -0500
Processing by API::V1::MembersController#destroy as */*
  Parameters: {"member"=>{"id"=>3}, "id"=>"3"}
  �[1m�[36mMember Load (1.0ms)�[0m  �[1m�[34mSELECT  "members".* FROM "members" WHERE "members"."uid" = $1 LIMIT $2�[0m  [["uid", "lassitergregg@gmail.com"], ["LIMIT", 1]]
  ↳ /Users/lassitergregg/.rvm/gems/ruby-2.5.0/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:97
  �[1m�[36mMember Load (0.7ms)�[0m  �[1m�[34mSELECT  "members".* FROM "members" WHERE "members"."id" = $1 LIMIT $2�[0m  [["id", 3], ["LIMIT", 1]]
  ↳ app/controllers/api/v1/members_controller.rb:57
  �[1m�[35m (0.2ms)�[0m  �[1m�[35mBEGIN�[0m
  ↳ app/controllers/api/v1/members_controller.rb:59
  �[1m�[36mFamilyMember Load (0.4ms)�[0m  �[1m�[34mSELECT "family_members".* FROM "family_members" WHERE "family_members"."member_id" = $1�[0m  [["member_id", 3]]
  ↳ app/controllers/api/v1/members_controller.rb:59
  �[1m�[36mFamilyMember Destroy (0.5ms)�[0m  �[1m�[31mDELETE FROM "family_members" WHERE "family_members"."id" = $1�[0m  [["id", 3]]
  ↳ app/controllers/api/v1/members_controller.rb:59
  �[1m�[36mActiveStorage::Attachment Load (1.2ms)�[0m  �[1m�[34mSELECT  "active_storage_attachments".* FROM "active_storage_attachments" WHERE "active_storage_attachments"."record_id" = $1 AND "active_storage_attachments"."record_type" = $2 AND "active_storage_attachments"."name" = $3 LIMIT $4�[0m  [["record_id", 3], ["record_type", "Member"], ["name", "avatar"], ["LIMIT", 1]]
  ↳ app/controllers/api/v1/members_controller.rb:59
  �[1m�[36mMember Destroy (0.4ms)�[0m  �[1m�[31mDELETE FROM "members" WHERE "members"."id" = $1�[0m  [["id", 3]]
  ↳ app/controllers/api/v1/members_controller.rb:59
  �[1m�[35m (2.2ms)�[0m  �[1m�[35mCOMMIT�[0m
  ↳ app/controllers/api/v1/members_controller.rb:59
[active_model_serializers] Rendered ActiveModel::Serializer::Null with Hash (0.06ms)
  �[1m�[35m (0.2ms)�[0m  �[1m�[35mBEGIN�[0m
  ↳ /Users/lassitergregg/.rvm/gems/ruby-2.5.0/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:97
  �[1m�[36mMember Load (0.8ms)�[0m  �[1m�[37mSELECT  "members".* FROM "members" WHERE "members"."id" = $1 LIMIT $2 FOR UPDATE�[0m  [["id", 3], ["LIMIT", 1]]
  ↳ /Users/lassitergregg/.rvm/gems/ruby-2.5.0/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:97
  �[1m�[35m (0.2ms)�[0m  �[1m�[31mROLLBACK�[0m
  ↳ /Users/lassitergregg/.rvm/gems/ruby-2.5.0/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:97
Completed 404 Not Found in 62859ms (Views: 0.7ms | ActiveRecord: 7.7ms)
  • Rails Stacktrace: this can be found in the log/development.log of your API.
ActiveRecord::RecordNotFound (Couldn't find Member with 'id'=3):
  
activerecord (5.2.1) lib/active_record/relation/finder_methods.rb:346:in `raise_record_not_found_exception!'
activerecord (5.2.1) lib/active_record/relation/finder_methods.rb:452:in `find_one'
activerecord (5.2.1) lib/active_record/relation/finder_methods.rb:431:in `find_with_ids'
activerecord (5.2.1) lib/active_record/relation/finder_methods.rb:69:in `find'
activerecord (5.2.1) lib/active_record/persistence.rb:606:in `block in reload'
activerecord (5.2.1) lib/active_record/scoping/default.rb:34:in `block in unscoped'
activerecord (5.2.1) lib/active_record/relation.rb:281:in `scoping'
activerecord (5.2.1) lib/active_record/scoping/default.rb:34:in `unscoped'
activerecord (5.2.1) lib/active_record/persistence.rb:606:in `reload'
activerecord (5.2.1) lib/active_record/attribute_methods/dirty.rb:34:in `reload'
activerecord (5.2.1) lib/active_record/associations.rb:255:in `reload'
activerecord (5.2.1) lib/active_record/autosave_association.rb:231:in `reload'
activerecord (5.2.1) lib/active_record/aggregations.rb:15:in `reload'
activerecord (5.2.1) lib/active_record/locking/pessimistic.rb:73:in `lock!'
activerecord (5.2.1) lib/active_record/locking/pessimistic.rb:83:in `block in with_lock'
activerecord (5.2.1) lib/active_record/connection_adapters/abstract/database_statements.rb:254:in `block in transaction'
activerecord (5.2.1) lib/active_record/connection_adapters/abstract/transaction.rb:239:in `block in within_new_transaction'
/Users/lassitergregg/.rvm/rubies/ruby-2.5.0/lib/ruby/2.5.0/monitor.rb:226:in `mon_synchronize'
activerecord (5.2.1) lib/active_record/connection_adapters/abstract/transaction.rb:236:in `within_new_transaction'
activerecord (5.2.1) lib/active_record/connection_adapters/abstract/database_statements.rb:254:in `transaction'
activerecord (5.2.1) lib/active_record/transactions.rb:212:in `transaction'
activerecord (5.2.1) lib/active_record/transactions.rb:301:in `transaction'
activerecord (5.2.1) lib/active_record/locking/pessimistic.rb:82:in `with_lock'
devise_token_auth (0.2.0) app/controllers/devise_token_auth/concerns/set_user_by_token.rb:122:in `block in update_auth_header'
devise_token_auth (0.2.0) app/controllers/devise_token_auth/concerns/set_user_by_token.rb:32:in `ensure_pristine_resource'
devise_token_auth (0.2.0) app/controllers/devise_token_auth/concerns/set_user_by_token.rb:119:in `update_auth_header'
activesupport (5.2.1) lib/active_support/callbacks.rb:426:in `block in make_lambda'
activesupport (5.2.1) lib/active_support/callbacks.rb:247:in `block in halting'
activesupport (5.2.1) lib/active_support/callbacks.rb:517:in `block in invoke_after'
activesupport (5.2.1) lib/active_support/callbacks.rb:517:in `each'
activesupport (5.2.1) lib/active_support/callbacks.rb:517:in `invoke_after'
activesupport (5.2.1) lib/active_support/callbacks.rb:133:in `run_callbacks'
actionpack (5.2.1) lib/abstract_controller/callbacks.rb:41:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'
activesupport (5.2.1) lib/active_support/notifications.rb:168:in `block in instrument'
activesupport (5.2.1) lib/active_support/notifications/instrumenter.rb:23:in `instrument'
activesupport (5.2.1) lib/active_support/notifications.rb:168:in `instrument'
actionpack (5.2.1) lib/action_controller/metal/instrumentation.rb:32:in `process_action'
actionpack (5.2.1) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'
activerecord (5.2.1) lib/active_record/railties/controller_runtime.rb:24:in `process_action'
actionpack (5.2.1) lib/abstract_controller/base.rb:134:in `process'
actionview (5.2.1) lib/action_view/rendering.rb:32:in `process'
actionpack (5.2.1) lib/action_controller/metal.rb:191:in `dispatch'
actionpack (5.2.1) lib/action_controller/metal.rb:252:in `dispatch'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:34:in `serve'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:52:in `block in serve'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:35:in `each'
actionpack (5.2.1) lib/action_dispatch/journey/router.rb:35:in `serve'
actionpack (5.2.1) lib/action_dispatch/routing/route_set.rb:840:in `call'
warden (1.2.7) lib/warden/manager.rb:36:in `block in call'
warden (1.2.7) lib/warden/manager.rb:35:in `catch'
warden (1.2.7) lib/warden/manager.rb:35:in `call'
rack (2.0.5) lib/rack/etag.rb:25:in `call'
rack (2.0.5) lib/rack/conditional_get.rb:38:in `call'
rack (2.0.5) lib/rack/head.rb:12:in `call'
activerecord (5.2.1) lib/active_record/migration.rb:559:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
activesupport (5.2.1) lib/active_support/callbacks.rb:98:in `run_callbacks'
actionpack (5.2.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'
railties (5.2.1) lib/rails/rack/logger.rb:38:in `call_app'
railties (5.2.1) lib/rails/rack/logger.rb:26:in `block in call'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in `block in tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:28:in `tagged'
activesupport (5.2.1) lib/active_support/tagged_logging.rb:71:in `tagged'
railties (5.2.1) lib/rails/rack/logger.rb:26:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'
request_store (1.4.1) lib/request_store/middleware.rb:19:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/request_id.rb:27:in `call'
rack (2.0.5) lib/rack/runtime.rb:22:in `call'
activesupport (5.2.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (5.2.1) lib/action_dispatch/middleware/static.rb:127:in `call'
rack (2.0.5) lib/rack/sendfile.rb:111:in `call'
railties (5.2.1) lib/rails/engine.rb:524:in `call'
puma (3.12.0) lib/puma/configuration.rb:225:in `call'
puma (3.12.0) lib/puma/server.rb:658:in `handle_request'
puma (3.12.0) lib/puma/server.rb:472:in `process_client'
puma (3.12.0) lib/puma/server.rb:332:in `block in run'
puma (3.12.0) lib/puma/thread_pool.rb:133:in `block in spawn_thread'
  • Environmental Info: How is your application different from the reference implementation? This may include (but is not limited to) the following details:

    • Custom Overrides: what have you done in terms of custom controller overrides?
      I've overridden part of the registration controller to create a few join model records on create.
@MaicolBen
Copy link
Collaborator

please don't use 0.2.0 unless you need #1159, use the latest, can you check again after that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants