title: How do I get current_user in ActionCable rails-5-api app?
body: <p>Why am I not able to retrieve <code>current_user</code> inside my channel or how should I retrieve <code>current_user</code>?</p>
  
  <p>What do I use?</p>
  
  <ul>
  <li>Rails 5.0.1 --api <strong><em>(I do NOT have any views NOR use coffee)</em></strong></li>
  <li>I use react-native app to test this <strong><em>(Works fine WITHOUT authorization)</em></strong></li>
  <li>I do NOT use devise for auth <strong><em>(I use JWT instead using Knock</em></strong>, so no cookies)</li>
  </ul>
  
  <p>Trying to get <code>current_user</code> inside my ActionCable channel as described in <a href="http://www.rubydoc.info/github/rails/actioncable/ActionCable/Connection/Base" rel="noreferrer">rubydoc.info</a></p>
  
  <p>The code looks like</p>
  
  <pre><code>class MessageChannel &lt; ApplicationCable::Channel
    identified_by :current_user
  
    def subscribed
      stream_from 'message_' + find_current_user_privileges
    end
  
    def unsubscribed
      # Any cleanup needed when channel is unsubscribed
    end
  
    protected
  
    def find_current_user_privileges
      if current_user.has_role? :admin
        'admin'
      else
        'user_' + current_user.id
      end
    end
  
  end
  </code></pre>
  
  <p>And running it, I get this error:</p>
  
  <pre><code>[NoMethodError - undefined method `identified_by' for MessageChannel:Class]
  </code></pre>
  
  <p>And if I remove <code>identified_by :current_user</code>, I get</p>
  
  <pre><code>[NameError - undefined local variable or method `current_user' for #&lt;MessageChannel:0x7ace398&gt;]
  </code></pre>