Class: Panda::Core::Subscribers::AuthenticationSubscriber
- Inherits:
-
Object
- Object
- Panda::Core::Subscribers::AuthenticationSubscriber
- Defined in:
- lib/panda/core/subscribers/authentication_subscriber.rb
Overview
Example subscriber for authentication events
To enable in your application, add to an initializer:
Panda::Core::Subscribers::AuthenticationSubscriber.attach
Class Method Summary collapse
Class Method Details
.attach ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/panda/core/subscribers/authentication_subscriber.rb', line 12 def attach # Subscribe to user creation ActiveSupport::Notifications.subscribe("panda.core.user_created") do |event| user = event.payload[:user] provider = event.payload[:provider] Rails.logger.info "[AuthSubscriber] New user created: #{user.email} via #{provider}" # Example: Send welcome email # UserMailer.welcome(user).deliver_later if defined?(UserMailer) # Example: Track analytics # Analytics.track("User Signup", user_id: user.id, provider: provider) if defined?(Analytics) end # Subscribe to user login ActiveSupport::Notifications.subscribe("panda.core.user_login") do |event| user = event.payload[:user] provider = event.payload[:provider] Rails.logger.info "[AuthSubscriber] User logged in: #{user.email} via #{provider}" # Example: Update last login time # user.touch(:last_login_at) if user.respond_to?(:last_login_at) # Example: Track analytics # Analytics.track("User Login", user_id: user.id, provider: provider) if defined?(Analytics) end # Subscribe to user logout ActiveSupport::Notifications.subscribe("panda.core.user_logout") do |event| user = event.payload[:user] Rails.logger.info "[AuthSubscriber] User logged out: #{user.email}" # Example: Clean up session data # SessionCleanupJob.perform_later(user.id) if defined?(SessionCleanupJob) end end |
.detach ⇒ Object
52 53 54 55 56 |
# File 'lib/panda/core/subscribers/authentication_subscriber.rb', line 52 def detach ActiveSupport::Notifications.unsubscribe("panda.core.user_created") ActiveSupport::Notifications.unsubscribe("panda.core.user_login") ActiveSupport::Notifications.unsubscribe("panda.core.user_logout") end |