Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add instructions for pulling the user id out of session storage #238

Merged
merged 1 commit into from
Jun 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions docs/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,37 @@ end
```
{% endcode %}


### Sorcery-based Authentication (user id is in session storage)

If you're using [Sorcery](https://github.com/Sorcery/sorcery) for authentication, you'd need to pull the user id out of the session store.

{% code title="app/channels/application\_cable/connection.rb" %}
```ruby
module ApplicationCable
class Connection < ActionCable::Connection::Base
identified_by :current_user

def connect
self.current_user = find_verified_user
end

protected

def find_verified_user
user_id = request.session.fetch("user_id", nil)

if verified_user = User.find_by(id: user_id)
verified_user
else
reject_unauthorized_connection
end
end
end
end
```
{% endcode %}

Now you're free to delegate current\_user. Be home by lunch:

{% code title="app/reflexes/example\_reflex.rb" %}
Expand Down