Rails 8 Native Authentication Generator

Command

by davila7 · Added 5mo ago

Claude

Install

npx claude-code-templates@latest --command=cli-tool/templates/ruby/examples/rails-app/.claude/commands --yes

Add to Claude

claude mcp add rails-8-native-authentication-generator

About

Rails 8 Native Authentication Generator

Generate Rails 8's built-in authentication system with modern security practices.

Purpose

This command helps you implement Rails 8's new native authentication system, eliminating the need for external gems like Devise for basic authentication needs.

Usage

/authentication

What this command does

  1. Generates authentication models with secure password handling
  2. Creates authentication controllers for login/logout/signup
  3. Adds authentication views with modern styling
  4. Implements session management with security best practices
  5. Sets up authentication helpers for controllers and views

Rails 8 Authentication Generator

# Generate authentication for User model
bin/rails generate authentication User

# Or specify custom model name
bin/rails generate authentication Account

# Generate with custom attributes
bin/rails generate authentication User first_name:string last_name:string

Generated User Model

# app/models/user.rb
class User < ApplicationRecord
  has_secure_password
  
  validates :email, presence: true, uniqueness: true
  validates :password, length: { minimum: 8 }, if: -> { new_record? || !password.blank? }
  
  normalizes :email, with: ->(email) { email.strip.downcase }
  
  before_save :normalize_email
  
  private
  
  def normalize_email
    self.email = email.downcase.strip
  end
end

Authentication Controller

# app/controllers/authentication_controller.rb
class AuthenticationController < ApplicationController
  skip_before_action :authenticate_user!, only: [:new, :create]
  
  def new
    # Login page
  end
  
  def create
    user = User.find_by(email: params[:email])
    
    if user&.authenticate(params[:password])
      login(user)
      redirect_to root_path, notice: 'Logged in successfully'
    else
      flash.now[:alert] = 'Invalid email or password'
      render :new, status: :unprocessable_entity
    end
  end
  
  

Tags

CodeAnalysisaitmplclaude-code-templates

From Our Store

View all →
Claude Code

Claude Code Power User Kit

$39+

Advanced Claude Code skills and configurations

OpenClaw

OpenClaw Business Starter Kit

$59+

Set Up Your AI Assistant in 60 Minutes