Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

Add Sentry user context to authentication concern

Josh Pigford763e222cddb9
diff --git a/app/controllers/concerns/authentication.rb b/app/controllers/concerns/authentication.rb
index a66d1b3f..9dc23942 100644
--- a/app/controllers/concerns/authentication.rb
+++ b/app/controllers/concerns/authentication.rb
@@ -4,11 +4,13 @@ module Authentication
included do
before_action :set_request_details
before_action :authenticate_user!
+ before_action :set_sentry_user
end
class_methods do
def skip_authentication(**options)
skip_before_action :authenticate_user!, **options
+ skip_before_action :set_sentry_user, **options
end
end
@@ -43,4 +45,17 @@ module Authentication
Current.user_agent = request.user_agent
Current.ip_address = request.ip
end
+
+ def set_sentry_user
+ return unless defined?(Sentry) && ENV["SENTRY_DSN"].present?
+
+ if Current.user
+ Sentry.set_user(
+ id: Current.user.id,
+ email: Current.user.email,
+ username: Current.user.display_name,
+ ip_address: Current.ip_address
+ )
+ end
+ end
end