BetterAuthy
A flexible authentication engine for Rails 8.0+ with multi-scope support. Enables multiple authenticatable models (users, accounts, admins) through a scope-based configuration system.
Features
- Multi-scope authentication (multiple user types)
- Session-based authentication with encrypted cookies
- Remember me functionality
- Password reset via email
- Sign-in tracking (IP, timestamp, count)
Quick Start
1. Add to Gemfile
gem "better_authy", "~> 0.2.0"2. Configure scope
# config/initializers/better_authy.rb
BetterAuthy.configure do |config|
config.scope :user do |scope|
scope.model_name = "User"
end
end3. Add to model
class User < ApplicationRecord
better_authy_authenticable :user
end4. Include controller helpers
class ApplicationController < ActionController::Base
include BetterAuthy::ControllerHelpers
end5. Mount engine
Rails.application.routes.draw do
mount BetterAuthy::Engine => "/auth"
end6. Create migration
class CreateUsers < ActiveRecord::Migration[8.0]
def change
create_table :users, id: :uuid do |t|
t.timestamps null: false
t.string :email, null: false
t.string :password_digest, null: false
t.string :remember_token_digest
t.datetime :remember_created_at
t.string :password_reset_token_digest
t.datetime :password_reset_sent_at
t.integer :sign_in_count, default: 0
t.datetime :current_sign_in_at, :last_sign_in_at
t.string :current_sign_in_ip, :last_sign_in_ip
t.index :email, unique: true
end
end
endUsage
# In controllers
before_action :authenticate_user!
current_user
user_signed_in?
# Manual sign in/out
sign_in_user(user, remember: true)
sign_out_userRoutes
| Path | Description |
|---|---|
/auth/user/login |
Login |
/auth/user/logout |
Logout |
/auth/user/signup |
Registration |
/auth/user/password/new |
Forgot password |
/auth/user/password/edit |
Reset password |
Documentation
See the docs/ folder for detailed guides:
- Installation - Complete setup instructions
- Configuration - All configuration options
- Models - Authenticable model setup
- Controller Helpers - Authentication methods
- Routes - Route helpers and customization
- Password Reset - Password reset flow
- Multi-Scope - Multiple user types
- Testing - Test setup and patterns
Dependencies
- Rails >= 8.0
- bcrypt ~> 3.1
- view_component ~> 4.0
- better_ui ~> 0.7
License
MIT License