Skip to content

pandev-srl/better_authy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

11 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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
end

3. Add to model

class User < ApplicationRecord
  better_authy_authenticable :user
end

4. Include controller helpers

class ApplicationController < ActionController::Base
  include BetterAuthy::ControllerHelpers
end

5. Mount engine

Rails.application.routes.draw do
  mount BetterAuthy::Engine => "/auth"
end

6. 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
end

Usage

# In controllers
before_action :authenticate_user!
current_user
user_signed_in?

# Manual sign in/out
sign_in_user(user, remember: true)
sign_out_user

Routes

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:

Dependencies

  • Rails >= 8.0
  • bcrypt ~> 3.1
  • view_component ~> 4.0
  • better_ui ~> 0.7

License

MIT License

About

πŸ” Rails 8.0+ authentication engine with multi-scope support. Multiple user types (users, admins, accounts) with independent sessions, remember me, password reset, and sign-in tracking.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors