Skip to main content

Join GoRails to continue learning

Subscribe to GoRails to get access to this episode and all other pro episodes, and access to our private Slack community of Ruby and Rails devs.

Subscribe to watch

Login to your account

ActionCable Introduction:

Realtime Notifications with ActionCable

53

Episode 125 · June 28, 2016

Learn how to implement realtime notifications with ActionCable

ActionCable


Resources

Authenticating ActionCable with Devise

# app/channels/application_cable/connection.rb
module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verfied_user
    end

    protected

    def find_verfied_user
      # We can just access Warden directly to find out if the user is logged in or not
      # Using Warden directly will give us access to that as it's what Devise uses internally for authentication
      if current_user = env['warden'].user
        current_user
      else
        reject_unauthorized_connection
      end
    end
  end
end
Transcripts

Subscribe or login to view the transcript for this episode.

Loading...

Subscribe to the newsletter

Join 18,000+ developers who get early access to new screencasts, articles, guides, updates, and more.

By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

More of a social being? We're also on Twitter and YouTube.