Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module ApplicationCable
- class Connection < ActionCable::Connection::Base
- identified_by :current_user
- def connect
- self.current_user = find_verified_user
- end
- private
- def find_verified_user
- begin
- header_array = request.headers[:HTTP_SEC_WEBSOCKET_PROTOCOL].split(',')
- token = header_array[header_array.length-1].strip
- decoded_token = JWT.decode token, nil, false
- if (current_user = ::Cliente.find(decoded_token[0]['cliente_id'].to_i))
- current_user
- else
- reject_unauthorized_connection
- end
- rescue
- reject_unauthorized_connection
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement