| 1 | module ApplicationCable |
| 2 | class Connection < ActionCable::Connection::Base |
| 3 | identified_by :current_user |
| 4 | |
| 5 | def connect |
| 6 | params = request.query_parameters() |
| 7 | access_token = params['accessToken'] |
| 8 | |
| 9 | self.current_user = find_verified_user access_token |
| 10 | end |
| 11 | |
| 12 | private |
| 13 | |
| 14 | def find_verified_user(access_token) |
| 15 | if verified_user = User.find_by(id: 1) |
| 16 | verified_user |
| 17 | else |
| 18 | reject_unauthorized_connection |
| 19 | end |
| 20 | end |
| 21 | end |
| 22 | end |