-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support clearance similar to devise/warden
Clearance is a fairly popular alternative. https://github.com/thoughtbot/clearance
- Loading branch information
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Bugsnag::Middleware | ||
class ClearanceUser | ||
COMMON_USER_FIELDS = [:email, :name, :first_name, :last_name, :created_at, :id] | ||
|
||
def initialize(bugsnag) | ||
@bugsnag = bugsnag | ||
end | ||
|
||
def call(notification) | ||
if notification.request_data[:rack_env] && | ||
notification.request_data[:rack_env]["clearance"] && | ||
notification.request_data[:rack_env]["clearance"].signed_in? && | ||
notification.request_data[:rack_env]["clearance"].current_user | ||
|
||
# Extract useful user information | ||
user = {} | ||
user_object = notification.request_data[:rack_env]["clearance"].current_user | ||
if user_object | ||
# Build the user info for this scope | ||
COMMON_USER_FIELDS.each do |field| | ||
user[field] = user_object.send(field) if user_object.respond_to?(field) | ||
end | ||
end | ||
|
||
# We merge the first warden scope down, so that it is the main "user" for the request | ||
notification.user = user unless user.empty? | ||
end | ||
|
||
@bugsnag.call(notification) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters