devise: wrong number of arguments (3 for 2)` in `serialize_from_cookie`
When I try to call current_user, sometimes I get wrong number of arguments (3 for 2) in the serialize_from_cookie method. Here’s the backtrace, starts at the bottom and goes up.
wrong number of arguments (3 for 2)
# devise/models/rememberable.rb in serialize_from_cookie at line 124
def serialize_from_cookie(id, remember_token)
# devise/strategies/rememberable.rb in authenticate! at line 20
resource = mapping.to.serialize_from_cookie(*remember_cookie)
# warden/strategies/base.rb in _run! at line 53
authenticate!
# warden/proxy.rb in block in _run_strategies_for at line 358
strategy._run!
# warden/proxy.rb in each at line 353
(strategies || args).each do |name|
# warden/proxy.rb in _run_strategies_for at line 353
(strategies || args).each do |name|
# warden/proxy.rb in _perform_authentication at line 323
_run_strategies_for(scope, args)
# warden/proxy.rb in authenticate at line 104
user, _opts = _perform_authentication(*args)
# devise/controllers/helpers.rb in current_user at line 124
@current_#{mapping} ||= warden.authenticate(scope: :#{mapping})
# app/controllers/application_controller.rb in set_raven_context at line 33application
current_user.try(:id)
# This is where it starts
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 15 (4 by maintainers)
same problem here from devise 3.5.3 to 4.2.0
I came across this issue when I was working on a legacy application which was running
devise v3.5.1. This was only happening on Chrome for me. I realised that I was working on another rails app which haddevise v4.2.0. What was happening was the cookie stored byv4.2.0was being read byv3.5.1.Since
serialize_from_cookienow takes variable length arguments in v4.2.0 instead of just 2 in v3.5.1, the method throws an error.Usually this should not happen as different apps will have different secret key to sign the cookie, but both my apps were using same secret key in
secret_key_base. I fixed this issue by changing the secret key inv3.5.1app.This can happen when you are upgrading devise from v3 to v4, your cookies written from older devise will be read by new devise, resulting in an error. To fix this please change the
secret_key_basefor your environments. In order to check if this is the issue, open your app in Incognito mode. If the app loads correctly, this is the issue.