<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Panos Dalitsouris</title>
    <description>The latest articles on DEV Community by Panos Dalitsouris (@panoscodes).</description>
    <link>https://dev.to/panoscodes</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F208032%2Fc287bc9b-2853-4433-a5de-984eda536ddd.png</url>
      <title>DEV Community: Panos Dalitsouris</title>
      <link>https://dev.to/panoscodes</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/panoscodes"/>
    <language>en</language>
    <item>
      <title>Get the current user in ActionCable</title>
      <dc:creator>Panos Dalitsouris</dc:creator>
      <pubDate>Mon, 07 Oct 2019 19:09:46 +0000</pubDate>
      <link>https://dev.to/panoscodes/get-the-current-user-in-actioncable-4d9b</link>
      <guid>https://dev.to/panoscodes/get-the-current-user-in-actioncable-4d9b</guid>
      <description>&lt;h4&gt;
  
  
  An easy way to get the current user using &lt;a href="https://github.com/waiting-for-dev/devise-jwt"&gt;devise-jwt&lt;/a&gt;
&lt;/h4&gt;

&lt;p&gt;When you “login”, &lt;strong&gt;devise-jwt&lt;/strong&gt; returns an Authorization header with a token&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Bearer eyJhbGciOiJIUzI1NiJ9.eyJpZCI6Miwic3ViIjoiMiIsInNjcCI6InVzZXIiLCJhdWQiOm51bGwsImlhdCI6MTU3MDM4OTcyNiwiZXhwIjoxNTcwMzkzMzI2LCJqdGkiOiI1NGZmY2YyOC1iNGFhLTQ3NDMtYTU5My1iOWJkYmIzNDRiOTIifQ.hcBKHd9n4r4s9-pHyshDyVm9zHnjF33SXXTQyGZljEY
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;You probably already know that.&lt;/p&gt;

&lt;p&gt;According to the &lt;a href="https://edgeguides.rubyonrails.org/action_cable_overview.html#connection-setup"&gt;docs&lt;/a&gt; if you are using cookies you can do the following to get the current user&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;verified_user&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find_by&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;id: &lt;/span&gt;&lt;span class="n"&gt;cookies&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;encrypted&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:user_id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;In case you use devise-jwt you could use following inside your connection.rb to find_verified_user 🎊&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



</description>
      <category>rails</category>
      <category>actioncable</category>
    </item>
  </channel>
</rss>
