Skip to content

Not load user on initial load from warden in development (config.eager_load = false) #210

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
le0pard opened this issue Jan 24, 2025 · 4 comments

Comments

@le0pard
Copy link

le0pard commented Jan 24, 2025

Hello. Interesting case with with config.eager_load = false (development) and warden gem.

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      $stdout.puts 'CONNECT!!!!!'
      $stdout.puts env['warden'].user(:user).inspect
      $stdout.puts 'CONNECT!!!!!'
      self.current_user = user_from_cookie || reject_unauthorized_connection
    end

    private

    def user_from_cookie
      env['warden'].user(:user)
    end
  end
end

So on first boot after connect to websocket we see this in logs:

CONNECT!!!!!
ws_rpc    | [[1], "$2a$13$DmKGCBG2.XC0p8ln4LAWpO"]
CONNECT!!!!!

which of course not "user", but information, which used to find user in session. But if I change code in project and reload page, will get valid user:

ws_rpc    | CONNECT!!!!!
ws_rpc    | #<User id: 1, email: ...>
ws_rpc    | CONNECT!!!!!

Also issue not present, if config.eager_load = true. Maybe it is not issue of a anycable, but rails or warden (or maybe it is known issue), but this is behaviour, which I reproduced. Session storage is cache storage in redis.

Versions:

  • ruby 3.3.7
  • rack (3.1.8)
  • rails (8.0.1)
  • devise (4.9.4)
  • warden (1.2.9)
  • anycable (1.5.2)
  • anycable-rails (1.5.6)
@palkan
Copy link
Member

palkan commented Jan 24, 2025

Thanks for reporting!

Looks it's related to this Devise issue: heartcombo/devise#5728

@le0pard
Copy link
Author

le0pard commented Jan 24, 2025

I had this patch in initializers file, because without this devise + rails 8 not working :)

@palkan
Copy link
Member

palkan commented Jan 24, 2025

As far as I understand, the following line is not being executed (even with the patch): https://github.com/heartcombo/devise/blob/fec67f98f26fcd9a79072e4581b1bd40d0c7fa1d/lib/devise/rails/routes.rb#L19

Could you please try adding the following (to the same initializer) to verify this hypothesis:

# ...
AnyCable.configure_server do
  Devise.configure_warden!
end

@le0pard
Copy link
Author

le0pard commented Jan 24, 2025

Thanks, @palkan . With

AnyCable.configure_server do
  Devise.configure_warden!
end

it start return user on initial app load. So looks like it is devise issue, not anycable

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

No branches or pull requests

2 participants