1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #36417 from notentered/patch-1

Add some examples for getting current_user
This commit is contained in:
Rafael França 2019-12-17 20:46:41 -03:00 committed by GitHub
commit c9316d1feb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
@ -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