Tôi đang cố gắng để có được cáp hành động làm việc với Devise.Rails Devise Cáp hành động
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user
def connect
self.current_user = find_verified_user
logger.add_tags 'ActionCable', current_user.name
end
protected
def find_verified_user
verified_user = User.find_by(id: cookies.signed['user.id'])
if verified_user && cookies.signed['user.expires_at'] > Time.now
verified_user
else
reject_unauthorized_connection
end
end
end
end
Nếu một người dùng được đăng nhập vào tôi vẫn nhận được nil
từ cookies.signed['user.id']
này đã làm việc tốt cho tôi ngoại trừ việc sử dụng của tôi không phải là mặc định bạn thiết lập với devise. Đối với trường hợp bạn có một người dùng khác đăng nhập chỉ cần thêm kiểu người dùng đó làm đối số tiếp theo như vậy 'verfied_user = env ['warden']. User ('admin_user')' – Timbinous
Mã đăng xuất phải: 'Warden :: Manager .before_logout do | user, auth, opts | scope = opts [: scope] auth.cookies.delete ("# {scope} .id") auth.cookies.delete ("# {scope} .expires_at") end' – prograils