From 763e222cddb90278e325713b86be6057af0d14c0 Mon Sep 17 00:00:00 2001 From: Josh Pigford Date: Tue, 25 Feb 2025 08:48:26 -0600 Subject: [PATCH] Add Sentry user context to authentication concern --- app/controllers/concerns/authentication.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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