Skip to content

Commit

Permalink
Merge pull request #36417 from notentered/patch-1
Browse files Browse the repository at this point in the history
Add some examples for getting current_user
  • Loading branch information
rafaelfranca committed Dec 17, 2019
2 parents 399b7be + 290d82a commit c9316d1
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion guides/source/action_cable_overview.md
Expand Up @@ -111,7 +111,7 @@ specific connection later. Note that anything marked as an identifier will autom
create a delegate by the same name on any channel instances created off the connection.

This example relies on the fact that you will already have handled authentication of the user
somewhere else in your application, and that a successful authentication sets a signed
somewhere else in your application, and that a successful authentication sets an encrypted
cookie with the user ID.

The cookie is then automatically sent to the connection instance when a new connection
Expand All @@ -120,6 +120,13 @@ by this same current user, you're also ensuring that you can later retrieve all
connections by a given user (and potentially disconnect them all if the user is deleted
or unauthorized).

If your authentication approach includes using a session, you use cookie store for the
session, your session cookie is named `_session` and the user ID key is `user_id` you
can use this approach:
```ruby
verified_user = User.find_by(id: cookies.encrypted['_session']['user_id'])
```

### Channels

A *channel* encapsulates a logical unit of work, similar to what a controller does in a
Expand Down

0 comments on commit c9316d1

Please sign in to comment.