Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## Unreleased

- Add `before_logout` hook to Warden that calls `ahoy.reset`

## 5.0.2 (2023-10-05)

- Excluded visits from Rails health check
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,20 @@ visitable :sign_up_visit

### Users

Ahoy automatically attaches the `current_user` to the visit. With [Devise](https://github.com/heartcombo/devise), it attaches the user even if they sign in after the visit starts.
Ahoy automatically attaches the `current_user` to the visit. With [Devise](https://github.com/heartcombo/devise), it attaches the user even if they sign in after the visit starts. It also resets the tracker's associated user after they sign out.

With other authentication frameworks, add this to the end of your sign in method:

```ruby
ahoy.authenticate(user)
```

Add this to the end of your sign out method:

```ruby
ahoy.reset
```

To see the visits for a given user, create an association:

```ruby
Expand Down
6 changes: 6 additions & 0 deletions lib/ahoy/warden.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
ahoy = Ahoy::Tracker.new(request: request)
ahoy.authenticate(user)
end

Warden::Manager.before_logout do |_, auth, _|
request = ActionDispatch::Request.new(auth.env)
ahoy = Ahoy::Tracker.new(request: request)
ahoy.reset
end