Skip to content

Cant log in - #<NoMethodError: undefined method `current_sign_in_at' for #<User:0x000055e053c79c58>> #1300

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

Closed
enriquemorenotent opened this issue Jun 8, 2019 · 6 comments

Comments

@enriquemorenotent
Copy link

I can't seem to be able to sign in, even though creating users works without a problem.

I added the gems into my Gemfile:

gem 'devise'
gem 'devise_token_auth'

I run the following commands:

$ bundle
$ rails generate devise:install
$ rails generate devise_token_auth:install User auth
$ rails db:migrate

This is my routes then:

$ rails routes                               
                  Prefix Verb   URI Pattern                                            Controller#Action
        new_user_session GET    /auth/sign_in(.:format)                                devise_token_auth/sessions#new
            user_session POST   /auth/sign_in(.:format)                                devise_token_auth/sessions#create
    destroy_user_session DELETE /auth/sign_out(.:format)                               devise_token_auth/sessions#destroy
       new_user_password GET    /auth/password/new(.:format)                           devise_token_auth/passwords#new
      edit_user_password GET    /auth/password/edit(.:format)                          devise_token_auth/passwords#edit
           user_password PATCH  /auth/password(.:format)                               devise_token_auth/passwords#update
                         PUT    /auth/password(.:format)                               devise_token_auth/passwords#update
                         POST   /auth/password(.:format)                               devise_token_auth/passwords#create
cancel_user_registration GET    /auth/cancel(.:format)                                 devise_token_auth/registrations#cancel
   new_user_registration GET    /auth/sign_up(.:format)                                devise_token_auth/registrations#new
  edit_user_registration GET    /auth/edit(.:format)                                   devise_token_auth/registrations#edit
       user_registration PATCH  /auth(.:format)                                        devise_token_auth/registrations#update
                         PUT    /auth(.:format)                                        devise_token_auth/registrations#update
                         DELETE /auth(.:format)                                        devise_token_auth/registrations#destroy
                         POST   /auth(.:format)                                        devise_token_auth/registrations#create
     auth_validate_token GET    /auth/validate_token(.:format)                         devise_token_auth/token_validations#validate_token

If I try to login with wrong credentials, I get this message:

{
    "success": false,
    "errors": [
        "Invalid login credentials. Please try again."
    ]
}

But if I try to login with the right credentials, I get this message:


    "status": 500,
    "error": "Internal Server Error",
    "exception": "#<NoMethodError: undefined method `current_sign_in_at' for #<User:0x00007f6bf80e4640>>",
    "traces": {
        "Application Trace": [],
        "Framework Trace": [
            {
                "id": 0,
                "trace": "activemodel (5.2.3) lib/active_model/attribute_methods.rb:430:in `method_missing'"
            },
            {
                "id": 1,
                "trace": "devise (4.6.2) lib/devise/models/trackable.rb:21:in `update_tracked_fields'"
            },
            {
                "id": 2,
                "trace": "devise (4.6.2) lib/devise/models/trackable.rb:39:in `update_tracked_fields!'"
            },
            {
                "id": 3,
                "trace": "devise (4.6.2) lib/devise/hooks/trackable.rb:9:in `block in <top (required)>'"
            },
            {
                "id": 4,
                "trace": "warden (1.2.8) lib/warden/hooks.rb:15:in `block in _run_callbacks'"
            },
            {
                "id": 5,
                "trace": "warden (1.2.8) lib/warden/hooks.rb:10:in `each'"
            },
            {
                "id": 6,
                "trace": "warden (1.2.8) lib/warden/hooks.rb:10:in `_run_callbacks'"
            },
            {
                "id": 7,
                "trace": "warden (1.2.8) lib/warden/manager.rb:52:in `_run_callbacks'"
            },
            {
                "id": 8,
                "trace": "warden (1.2.8) lib/warden/proxy.rb:191:in `set_user'"
            },
            {
                "id": 9,
                "trace": "devise (4.6.2) lib/devise/controllers/sign_in_out.rb:53:in `sign_in'"
            },
            {
                "id": 10,
                "trace": "devise_token_auth (1.1.0) app/controllers/devise_token_auth/sessions_controller.rb:32:in `create'"
            },
            {
                "id": 11,
                "trace": "actionpack (5.2.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'"
            },
            {
                "id": 12,
                "trace": "actionpack (5.2.3) lib/abstract_controller/base.rb:194:in `process_action'"
            },
            {
                "id": 13,
                "trace": "actionpack (5.2.3) lib/action_controller/metal/rendering.rb:30:in `process_action'"
            },
            {
                "id": 14,
                "trace": "actionpack (5.2.3) lib/abstract_controller/callbacks.rb:42:in `block in process_action'"
            },
            {
                "id": 15,
                "trace": "activesupport (5.2.3) lib/active_support/callbacks.rb:132:in `run_callbacks'"
            },
            {
                "id": 16,
                "trace": "actionpack (5.2.3) lib/abstract_controller/callbacks.rb:41:in `process_action'"
            },
            {
                "id": 17,
                "trace": "actionpack (5.2.3) lib/action_controller/metal/rescue.rb:22:in `process_action'"
            },
            {
                "id": 18,
                "trace": "actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'"
            },
            {
                "id": 19,
                "trace": "activesupport (5.2.3) lib/active_support/notifications.rb:168:in `block in instrument'"
            },
            {
                "id": 20,
                "trace": "activesupport (5.2.3) lib/active_support/notifications/instrumenter.rb:23:in `instrument'"
            },
            {
                "id": 21,
                "trace": "activesupport (5.2.3) lib/active_support/notifications.rb:168:in `instrument'"
            },
            {
                "id": 22,
                "trace": "actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:32:in `process_action'"
            },
            {
                "id": 23,
                "trace": "actionpack (5.2.3) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'"
            },
            {
                "id": 24,
                "trace": "activerecord (5.2.3) lib/active_record/railties/controller_runtime.rb:24:in `process_action'"
            },
            {
                "id": 25,
                "trace": "actionpack (5.2.3) lib/abstract_controller/base.rb:134:in `process'"
            },
            {
                "id": 26,
                "trace": "actionpack (5.2.3) lib/action_controller/metal.rb:191:in `dispatch'"
            },
            {
                "id": 27,
                "trace": "actionpack (5.2.3) lib/action_controller/metal.rb:252:in `dispatch'"
            },
            {
                "id": 28,
                "trace": "actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'"
            },
            {
                "id": 29,
                "trace": "actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:34:in `serve'"
            },
            {
                "id": 30,
                "trace": "actionpack (5.2.3) lib/action_dispatch/routing/mapper.rb:18:in `block in <class:Constraints>'"
            },
            {
                "id": 31,
                "trace": "actionpack (5.2.3) lib/action_dispatch/routing/mapper.rb:48:in `serve'"
            },
            {
                "id": 32,
                "trace": "actionpack (5.2.3) lib/action_dispatch/journey/router.rb:52:in `block in serve'"
            },
            {
                "id": 33,
                "trace": "actionpack (5.2.3) lib/action_dispatch/journey/router.rb:35:in `each'"
            },
            {
                "id": 34,
                "trace": "actionpack (5.2.3) lib/action_dispatch/journey/router.rb:35:in `serve'"
            },
            {
                "id": 35,
                "trace": "actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:840:in `call'"
            },
            {
                "id": 36,
                "trace": "warden (1.2.8) lib/warden/manager.rb:36:in `block in call'"
            },
            {
                "id": 37,
                "trace": "warden (1.2.8) lib/warden/manager.rb:34:in `catch'"
            },
            {
                "id": 38,
                "trace": "warden (1.2.8) lib/warden/manager.rb:34:in `call'"
            },
            {
                "id": 39,
                "trace": "rack (2.0.7) lib/rack/etag.rb:25:in `call'"
            },
            {
                "id": 40,
                "trace": "rack (2.0.7) lib/rack/conditional_get.rb:38:in `call'"
            },
            {
                "id": 41,
                "trace": "rack (2.0.7) lib/rack/head.rb:12:in `call'"
            },
            {
                "id": 42,
                "trace": "activerecord (5.2.3) lib/active_record/migration.rb:559:in `call'"
            },
            {
                "id": 43,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'"
            },
            {
                "id": 44,
                "trace": "activesupport (5.2.3) lib/active_support/callbacks.rb:98:in `run_callbacks'"
            },
            {
                "id": 45,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:26:in `call'"
            },
            {
                "id": 46,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'"
            },
            {
                "id": 47,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'"
            },
            {
                "id": 48,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'"
            },
            {
                "id": 49,
                "trace": "railties (5.2.3) lib/rails/rack/logger.rb:38:in `call_app'"
            },
            {
                "id": 50,
                "trace": "railties (5.2.3) lib/rails/rack/logger.rb:26:in `block in call'"
            },
            {
                "id": 51,
                "trace": "activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `block in tagged'"
            },
            {
                "id": 52,
                "trace": "activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged'"
            },
            {
                "id": 53,
                "trace": "activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged'"
            },
            {
                "id": 54,
                "trace": "railties (5.2.3) lib/rails/rack/logger.rb:26:in `call'"
            },
            {
                "id": 55,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'"
            },
            {
                "id": 56,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call'"
            },
            {
                "id": 57,
                "trace": "rack (2.0.7) lib/rack/runtime.rb:22:in `call'"
            },
            {
                "id": 58,
                "trace": "activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'"
            },
            {
                "id": 59,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'"
            },
            {
                "id": 60,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/static.rb:127:in `call'"
            },
            {
                "id": 61,
                "trace": "rack (2.0.7) lib/rack/sendfile.rb:111:in `call'"
            },
            {
                "id": 62,
                "trace": "rack-cors (1.0.3) lib/rack/cors.rb:95:in `call'"
            },
            {
                "id": 63,
                "trace": "railties (5.2.3) lib/rails/engine.rb:524:in `call'"
            },
            {
                "id": 64,
                "trace": "puma (3.12.1) lib/puma/configuration.rb:227:in `call'"
            },
            {
                "id": 65,
                "trace": "puma (3.12.1) lib/puma/server.rb:660:in `handle_request'"
            },
            {
                "id": 66,
                "trace": "puma (3.12.1) lib/puma/server.rb:474:in `process_client'"
            },
            {
                "id": 67,
                "trace": "puma (3.12.1) lib/puma/server.rb:334:in `block in run'"
            },
            {
                "id": 68,
                "trace": "puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread'"
            }
        ],
        "Full Trace": [
            {
                "id": 0,
                "trace": "activemodel (5.2.3) lib/active_model/attribute_methods.rb:430:in `method_missing'"
            },
            {
                "id": 1,
                "trace": "devise (4.6.2) lib/devise/models/trackable.rb:21:in `update_tracked_fields'"
            },
            {
                "id": 2,
                "trace": "devise (4.6.2) lib/devise/models/trackable.rb:39:in `update_tracked_fields!'"
            },
            {
                "id": 3,
                "trace": "devise (4.6.2) lib/devise/hooks/trackable.rb:9:in `block in <top (required)>'"
            },
            {
                "id": 4,
                "trace": "warden (1.2.8) lib/warden/hooks.rb:15:in `block in _run_callbacks'"
            },
            {
                "id": 5,
                "trace": "warden (1.2.8) lib/warden/hooks.rb:10:in `each'"
            },
            {
                "id": 6,
                "trace": "warden (1.2.8) lib/warden/hooks.rb:10:in `_run_callbacks'"
            },
            {
                "id": 7,
                "trace": "warden (1.2.8) lib/warden/manager.rb:52:in `_run_callbacks'"
            },
            {
                "id": 8,
                "trace": "warden (1.2.8) lib/warden/proxy.rb:191:in `set_user'"
            },
            {
                "id": 9,
                "trace": "devise (4.6.2) lib/devise/controllers/sign_in_out.rb:53:in `sign_in'"
            },
            {
                "id": 10,
                "trace": "devise_token_auth (1.1.0) app/controllers/devise_token_auth/sessions_controller.rb:32:in `create'"
            },
            {
                "id": 11,
                "trace": "actionpack (5.2.3) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'"
            },
            {
                "id": 12,
                "trace": "actionpack (5.2.3) lib/abstract_controller/base.rb:194:in `process_action'"
            },
            {
                "id": 13,
                "trace": "actionpack (5.2.3) lib/action_controller/metal/rendering.rb:30:in `process_action'"
            },
            {
                "id": 14,
                "trace": "actionpack (5.2.3) lib/abstract_controller/callbacks.rb:42:in `block in process_action'"
            },
            {
                "id": 15,
                "trace": "activesupport (5.2.3) lib/active_support/callbacks.rb:132:in `run_callbacks'"
            },
            {
                "id": 16,
                "trace": "actionpack (5.2.3) lib/abstract_controller/callbacks.rb:41:in `process_action'"
            },
            {
                "id": 17,
                "trace": "actionpack (5.2.3) lib/action_controller/metal/rescue.rb:22:in `process_action'"
            },
            {
                "id": 18,
                "trace": "actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:34:in `block in process_action'"
            },
            {
                "id": 19,
                "trace": "activesupport (5.2.3) lib/active_support/notifications.rb:168:in `block in instrument'"
            },
            {
                "id": 20,
                "trace": "activesupport (5.2.3) lib/active_support/notifications/instrumenter.rb:23:in `instrument'"
            },
            {
                "id": 21,
                "trace": "activesupport (5.2.3) lib/active_support/notifications.rb:168:in `instrument'"
            },
            {
                "id": 22,
                "trace": "actionpack (5.2.3) lib/action_controller/metal/instrumentation.rb:32:in `process_action'"
            },
            {
                "id": 23,
                "trace": "actionpack (5.2.3) lib/action_controller/metal/params_wrapper.rb:256:in `process_action'"
            },
            {
                "id": 24,
                "trace": "activerecord (5.2.3) lib/active_record/railties/controller_runtime.rb:24:in `process_action'"
            },
            {
                "id": 25,
                "trace": "actionpack (5.2.3) lib/abstract_controller/base.rb:134:in `process'"
            },
            {
                "id": 26,
                "trace": "actionpack (5.2.3) lib/action_controller/metal.rb:191:in `dispatch'"
            },
            {
                "id": 27,
                "trace": "actionpack (5.2.3) lib/action_controller/metal.rb:252:in `dispatch'"
            },
            {
                "id": 28,
                "trace": "actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:52:in `dispatch'"
            },
            {
                "id": 29,
                "trace": "actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:34:in `serve'"
            },
            {
                "id": 30,
                "trace": "actionpack (5.2.3) lib/action_dispatch/routing/mapper.rb:18:in `block in <class:Constraints>'"
            },
            {
                "id": 31,
                "trace": "actionpack (5.2.3) lib/action_dispatch/routing/mapper.rb:48:in `serve'"
            },
            {
                "id": 32,
                "trace": "actionpack (5.2.3) lib/action_dispatch/journey/router.rb:52:in `block in serve'"
            },
            {
                "id": 33,
                "trace": "actionpack (5.2.3) lib/action_dispatch/journey/router.rb:35:in `each'"
            },
            {
                "id": 34,
                "trace": "actionpack (5.2.3) lib/action_dispatch/journey/router.rb:35:in `serve'"
            },
            {
                "id": 35,
                "trace": "actionpack (5.2.3) lib/action_dispatch/routing/route_set.rb:840:in `call'"
            },
            {
                "id": 36,
                "trace": "warden (1.2.8) lib/warden/manager.rb:36:in `block in call'"
            },
            {
                "id": 37,
                "trace": "warden (1.2.8) lib/warden/manager.rb:34:in `catch'"
            },
            {
                "id": 38,
                "trace": "warden (1.2.8) lib/warden/manager.rb:34:in `call'"
            },
            {
                "id": 39,
                "trace": "rack (2.0.7) lib/rack/etag.rb:25:in `call'"
            },
            {
                "id": 40,
                "trace": "rack (2.0.7) lib/rack/conditional_get.rb:38:in `call'"
            },
            {
                "id": 41,
                "trace": "rack (2.0.7) lib/rack/head.rb:12:in `call'"
            },
            {
                "id": 42,
                "trace": "activerecord (5.2.3) lib/active_record/migration.rb:559:in `call'"
            },
            {
                "id": 43,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'"
            },
            {
                "id": 44,
                "trace": "activesupport (5.2.3) lib/active_support/callbacks.rb:98:in `run_callbacks'"
            },
            {
                "id": 45,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/callbacks.rb:26:in `call'"
            },
            {
                "id": 46,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'"
            },
            {
                "id": 47,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:61:in `call'"
            },
            {
                "id": 48,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/show_exceptions.rb:33:in `call'"
            },
            {
                "id": 49,
                "trace": "railties (5.2.3) lib/rails/rack/logger.rb:38:in `call_app'"
            },
            {
                "id": 50,
                "trace": "railties (5.2.3) lib/rails/rack/logger.rb:26:in `block in call'"
            },
            {
                "id": 51,
                "trace": "activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `block in tagged'"
            },
            {
                "id": 52,
                "trace": "activesupport (5.2.3) lib/active_support/tagged_logging.rb:28:in `tagged'"
            },
            {
                "id": 53,
                "trace": "activesupport (5.2.3) lib/active_support/tagged_logging.rb:71:in `tagged'"
            },
            {
                "id": 54,
                "trace": "railties (5.2.3) lib/rails/rack/logger.rb:26:in `call'"
            },
            {
                "id": 55,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/remote_ip.rb:81:in `call'"
            },
            {
                "id": 56,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/request_id.rb:27:in `call'"
            },
            {
                "id": 57,
                "trace": "rack (2.0.7) lib/rack/runtime.rb:22:in `call'"
            },
            {
                "id": 58,
                "trace": "activesupport (5.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'"
            },
            {
                "id": 59,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/executor.rb:14:in `call'"
            },
            {
                "id": 60,
                "trace": "actionpack (5.2.3) lib/action_dispatch/middleware/static.rb:127:in `call'"
            },
            {
                "id": 61,
                "trace": "rack (2.0.7) lib/rack/sendfile.rb:111:in `call'"
            },
            {
                "id": 62,
                "trace": "rack-cors (1.0.3) lib/rack/cors.rb:95:in `call'"
            },
            {
                "id": 63,
                "trace": "railties (5.2.3) lib/rails/engine.rb:524:in `call'"
            },
            {
                "id": 64,
                "trace": "puma (3.12.1) lib/puma/configuration.rb:227:in `call'"
            },
            {
                "id": 65,
                "trace": "puma (3.12.1) lib/puma/server.rb:660:in `handle_request'"
            },
            {
                "id": 66,
                "trace": "puma (3.12.1) lib/puma/server.rb:474:in `process_client'"
            },
            {
                "id": 67,
                "trace": "puma (3.12.1) lib/puma/server.rb:334:in `block in run'"
            },
            {
                "id": 68,
                "trace": "puma (3.12.1) lib/puma/thread_pool.rb:135:in `block in spawn_thread'"
            }
        ]
    }

I am using ruby 2.5.1 and rails 5.2.3

What is wrong??

@codingedward
Copy link

I solved this by installing version one of the gem as:

gem 'devise_token_auth', '1.0.0'

I run the following commands:

$ bundle install
$ rails generate devise_token_auth:install User auth
$ rails db:migrate

Note that you don't have to install devise yourself.

@farverio
Copy link

farverio commented Jun 18, 2019

Just got this error, too. Tried downgrading to '1.0.0' but no luck yet

Update:
It appears Devise might have made some breaking changes that require trackable by default. To fix, just include the following in your devise_token_auth migration file before running:

      ## Trackable
      t.integer  :sign_in_count, default: 0, null: false
      t.datetime :current_sign_in_at
      t.datetime :last_sign_in_at
      t.string   :current_sign_in_ip
      t.string   :last_sign_in_ip

@MaicolBen
Copy link
Collaborator

@farverio

It appears Devise might have made some breaking changes that require trackable by default

Are you sure? Check heartcombo/devise#4857

I removed that field and it worked for me so you might be using the trackable module

@MaicolBen
Copy link
Collaborator

@enriquemorenotent What devise version do you have? What devise modules do you have?

@rnevius
Copy link

rnevius commented Oct 28, 2019

Devise no longer includes Trackable in its model generator. If you need Trackable, generate a migration with the fields mentioned by @farverio. Otherwise, remove the :trackable devise configuration option from your user class.

@dayudodo
Copy link

dayudodo commented Sep 18, 2023

remove trackable in your user.rb file, like this:

class User < ActiveRecord::Base
   # devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable
  devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable

tested in rails 7.0.6, devise: 4.9.2

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

6 participants