百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

authtrail

> 编程语言
开源

跟踪 Devise 登录活动

566 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

跟踪 Devise 登录活动

AuthTrail

Track Devise login activity

:tangerine: Battle-tested at Instacart

Installation

Add this line to your application’s Gemfile:

ruby
gem "authtrail"

To encrypt email and IP addresses with Lockbox, install Lockbox and Blind Index and run:

bash
rails generate authtrail:install --encryption=lockbox
rails db:migrate

To use Active Record encryption, run:

bash
rails generate authtrail:install --encryption=activerecord
rails db:migrate

If you prefer not to encrypt data, run:

bash
rails generate authtrail:install --encryption=none
rails db:migrate

To enable geocoding, see the Geocoding section.

How It Works

A LoginActivity record is created every time a user tries to login. You can then use this information to detect suspicious behavior. Data includes:

  • scope - Devise scope
  • strategy - Devise strategy
  • identity - email address
  • success - whether the login succeeded
  • failure_reason - if the login failed
  • user - the user if the login succeeded
  • context - controller and action
  • ip - IP address
  • user_agent and referrer - from browser
  • city, region, country, latitude, and longitude - from IP
  • created_at - time of event

Features

Exclude certain attempts from tracking - useful if you run acceptance tests

ruby
AuthTrail.exclude_method = lambda do |data|
  data[:identity] == "[email protected]"
end

Add or modify data - also add new fields to the login_activities table if needed

ruby
AuthTrail.transform_method = lambda do |data, request|
  data[:request_id] = request.request_id
end

Store the user on failed attempts

ruby
AuthTrail.transform_method = lambda do |data, request|
  data[:user] ||= User.find_by(email: data[:identity])
end

Write data somewhere other than the login_activities table

ruby
AuthTrail.track_method = lambda do |data|
  # code
end

Use a custom identity method

ruby
AuthTrail.identity_method = lambda do |request, opts, user|
  if user
    user.email
  else
    request.params.dig(opts[:scope], :email)
  end
end

Associate login activity with your user model

ruby
class User "]
  data[:region] = request.headers[""]
  data[:city] = request.headers[""]
end

Check out this example

Data Retention

Delete older data with:

ruby
LoginActivity.where("created_at < ?", 2.years.ago).in_batches.delete_all

Delete data for a specific user with:

ruby
LoginActivity.where(user_id: 1, user_type: "User").in_batches.delete_all

Other Notes

We recommend using this in addition to Devise’s Lockable module and Rack::Attack.

Check out Hardening Devise and Secure Rails for more best practices.

History

View the changelog

Contributing

Everyone is encouraged to help improve this project. Here are a few ways you can help:

  • Report bugs
  • Fix bugs and submit pull requests
  • Write, clarify, or fix documentation
  • Suggest or add new features

To get started with development and testing:

bash
git clone https://github.com/ankane/authtrail.git
cd authtrail
bundle install
bundle exec rake test

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言