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

Devise authentication/sessions not working #181

Closed
quadlol opened this issue Mar 8, 2023 · 1 comment
Closed

Devise authentication/sessions not working #181

quadlol opened this issue Mar 8, 2023 · 1 comment

Comments

@quadlol
Copy link

quadlol commented Mar 8, 2023

Hi, it seems that cookies/session doesn't work with anycable.

Before I had added anycable, I authenticated like this

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user 
    def connect
      self.current_user = find_user
    end

    def find_user
      if (current_user = env["warden"].user)
        current_user
      else
        reject_unauthorized_connection
      end
    rescue UncaughtThrowError
      nil
    end

This always worked. Now I installed anycable and cookies/sessions are empty.

[13] pry(#<ApplicationCable::Connection>)> cookies
=> #<ActionDispatch::Cookies::CookieJar:0x000000010dc0c8e0 @committed=false, @cookies={}, @delete_cookies={}, @request=#<ActionDispatch::Request GET "http://localhost/cable" for 127.0.0.1>, @set_cookies={}>

I have tried almost everything

env["warden"].user(:user)
AnyCable::Rails::Rack.middleware.use Warden::Manager do |config|
  Devise.warden_config = config
end

# frozen_string_literal: true

Warden::Manager.after_set_user do |user,auth,opts|
  scope = opts[:scope]
  auth.cookies.signed["#{scope}_id"] = user.id
end

Warden::Manager.before_logout do |user, auth, opts|
  scope = opts[:scope]
  auth.cookies.signed["#{scope}_id"] = nil
end

All of them are empty, it doesn't matter what I do. I am using the default Rails session_store and caching is off.

Why am I not able to access the current session in connection?

Tell us about your environment

Ruby version: 3.1

Rails version: 6.1

anycable gem version: 1.3

anycable-rails gem version: 1.3.7

grpc gem version: 1.52

@quadlol quadlol closed this as completed Mar 9, 2023
@RedShore117
Copy link

Hi, it seems that cookies/session doesn't work with anycable.

Hello i have same problem, can u tell me how u figure it out? thanks!

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