{"action":"created","issue":{"url":"https://api.github.com/repos/rails/rails/issues/25882","repository_url":"https://api.github.com/repos/rails/rails","labels_url":"https://api.github.com/repos/rails/rails/issues/25882/labels{/name}","comments_url":"https://api.github.com/repos/rails/rails/issues/25882/comments","events_url":"https://api.github.com/repos/rails/rails/issues/25882/events","html_url":"https://github.com/rails/rails/issues/25882","id":166200778,"number":25882,"title":"ActionCable doesn't reconnect / update after cookies are changed [Chrome / Firefox only]","user":{"login":"ideo-henry","id":13455636,"avatar_url":"https://avatars.githubusercontent.com/u/13455636?v=3","gravatar_id":"","url":"https://api.github.com/users/ideo-henry","html_url":"https://github.com/ideo-henry","followers_url":"https://api.github.com/users/ideo-henry/followers","following_url":"https://api.github.com/users/ideo-henry/following{/other_user}","gists_url":"https://api.github.com/users/ideo-henry/gists{/gist_id}","starred_url":"https://api.github.com/users/ideo-henry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ideo-henry/subscriptions","organizations_url":"https://api.github.com/users/ideo-henry/orgs","repos_url":"https://api.github.com/users/ideo-henry/repos","events_url":"https://api.github.com/users/ideo-henry/events{/privacy}","received_events_url":"https://api.github.com/users/ideo-henry/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rails/rails/labels/actioncable","name":"actioncable","color":"bfdadc"},{"url":"https://api.github.com/repos/rails/rails/labels/needs%20work","name":"needs work","color":"000000"}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-07-18T21:43:48Z","updated_at":"2016-08-02T14:26:32Z","closed_at":null,"body":"### Steps to reproduce\r\nIn production mode, when a user is logged in and changes the cookies, the actioncable :identified_by doesn't get updated.\r\n\r\nHere is how the cookies are updated (student users are logged in):\r\n```ruby\r\n\tdef create\r\n\t\t@student = Student.find_by_email(params[:student_session][:email])\r\n\t\tif @student && @student.authenticate(params[:student_session][:password])\r\n\t\t\tsession[:student_id] = @student.id\r\n\t\t\tcookies.signed[:student_id] = @student.id\r\n\t\t\tredirect_to '/student_space'\r\n\t\telse\r\n\t\t\t# restrict access\r\n\t\tend\r\n\tend\r\n```\r\n\r\nHere is the actioncable code:\r\n```ruby\r\nmodule ApplicationCable\r\n  class Connection < ActionCable::Connection::Base\r\n  \tidentified_by :current_student\r\n\r\n  \tdef connect\r\n      if find_verified_user != nil\r\n        self.current_student = find_verified_student\r\n      end\r\n  \tend\r\n\r\n  \tprivate\r\n  \t\tdef find_verified_student\r\n  \t\t\tif (current_student = Student.find_by(id: cookies.signed[:student_id]))\r\n  \t\t\t\treturn current_student\r\n  \t\t\tend\r\n  \t\tend\r\n  end\r\nend\r\n```\r\n\r\nThe subscribing part:\r\n```ruby\r\n  def subscribed\r\n  \tif (current_student != nil)\r\n    \tstream_from \"chat_channel_#{current_student.id}\"\r\n   \tend\r\n  end\r\n```\r\n\r\n### Expected behavior\r\nThe actioncable should re-connect and update where it's streaming from when cookies are changed.\r\n\r\n### Actual behavior\r\nIn production mode, and in Chrome / Firefox only, the connection doesn't get updated when the cookies are changed, thus, it's not streaming from the right streams.\r\n\r\n### System configuration\r\n**Rails version**: 5.0.0\r\n\r\n**Ruby version**: 2.3\r\n"},"comment":{"url":"https://api.github.com/repos/rails/rails/issues/comments/236921053","html_url":"https://github.com/rails/rails/issues/25882#issuecomment-236921053","issue_url":"https://api.github.com/repos/rails/rails/issues/25882","id":236921053,"user":{"login":"danielrhodes","id":120044,"avatar_url":"https://avatars.githubusercontent.com/u/120044?v=3","gravatar_id":"","url":"https://api.github.com/users/danielrhodes","html_url":"https://github.com/danielrhodes","followers_url":"https://api.github.com/users/danielrhodes/followers","following_url":"https://api.github.com/users/danielrhodes/following{/other_user}","gists_url":"https://api.github.com/users/danielrhodes/gists{/gist_id}","starred_url":"https://api.github.com/users/danielrhodes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danielrhodes/subscriptions","organizations_url":"https://api.github.com/users/danielrhodes/orgs","repos_url":"https://api.github.com/users/danielrhodes/repos","events_url":"https://api.github.com/users/danielrhodes/events{/privacy}","received_events_url":"https://api.github.com/users/danielrhodes/received_events","type":"User","site_admin":false},"created_at":"2016-08-02T14:26:31Z","updated_at":"2016-08-02T14:26:31Z","body":"Not sure if it's in the guides, but here is some documentation:\n\nhttps://github.com/rails/rails/blob/master/actioncable/app/assets/javascripts/action_cable/consumer.coffee\n\n> On Aug 2, 2016, at 21:20, ideo-henry <notifications@github.com> wrote:\n> \n> @danielrhodes Thank you so much for pointing this out! How can I explicitly re-connect to rails actioncable from front-end JavaScript calls and / or back-end rails code?\n> \n> —\n> You are receiving this because you were mentioned.\n> Reply to this email directly, view it on GitHub, or mute the thread.\n> \n"}}
{"actor":{"display_login":"danielrhodes"}}