Module: CustomerServiceIm::Connection

Extended by:
ActiveSupport::Concern
Defined in:
app/channels/concerns/customer_service_im/connection.rb

Instance Method Summary collapse

Instance Method Details

#connectObject



12
13
14
# File 'app/channels/concerns/customer_service_im/connection.rb', line 12

def connect
  self.current_user = find_user
end

#find_userObject



16
17
18
19
20
21
22
23
24
# File 'app/channels/concerns/customer_service_im/connection.rb', line 16

def find_user
  payload, = JWT.decode(request.params[:token], CustomerServiceIm.jwt_secret, true, { algorithm: "HS256" })

  payload["data"]["user_type"].classify.constantize.find(payload["data"]["user_id"])
rescue JWT::DecodeError => e
  logger = Logger.new Rails.root.join("log/jwt.log")
  logger.error("JWT Decode Error: #{e}")
  raise e
end

#included(base) ⇒ Object



6
7
8
9
10
# File 'app/channels/concerns/customer_service_im/connection.rb', line 6

def included(base)
  base.class_eval do
    identified_by :current_user
  end
end