AuthTrail provides several configuration hooks to modify how login activities are captured and stored.
Exclude certain attempts
Use AuthTrail.exclude_method to skip tracking for specific data (e.g., automated tests).
Transform or add data
Use AuthTrail.transform_method to modify the data hash or add new fields (like request_id) before saving. You can also use this to associate a user on failed attempts by looking them up via the identity.
Custom storage
Use AuthTrail.track_method to write data to a destination other than the default login_activities table.
Custom identity resolution
Use AuthTrail.identity_method to define how the login identity (e.g., email) is extracted from the request or user object.
# Exclude specific identities
AuthTrail.exclude_method = lambda do |data|
data[:identity] == "capybara@example.org"
end
# Add request_id to the data
AuthTrail.transform_method = lambda do |data, request|
data[:request_id] = request.request_id
end
# Store the user on failed attempts
AuthTrail.transform_method = lambda do |data, request|
data[:user] ||= User.find_by(email: data[:identity])
end
# Write to a custom destination
AuthTrail.track_method = lambda do |data|
# custom logic here
end
# Custom identity method
AuthTrail.identity_method = lambda do |request, opts, user|
if user
user.email
else
request.params.dig(opts[:scope], :email)
end
end