agentsclimarketplace

Rails auth with devise

Skill Shoebtamboli/rails_claude_skills/lib/generators/claude/skills_library/rails-auth-with-devise

A Rails generator gem that scaffolds Claude AI skills and agents for any Rails project.

Install
npx -y skills add Shoebtamboli/rails_claude_skills --skill rails-auth-with-devise

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 14 stars14 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Complete authentication setup for Ruby on Rails applications using Devise. Use when: (1) Setting up user authentication in a Rails app, (2) Adding sign in/sign up/sign out functionality, (3) Implementing email confirmation, password recovery, or account locking, (4) Configuring OmniAuth social login, (5) Adding multiple user models (User/Admin), (6) Customizing Devise views or controllers, (7) Testing authentication with RSpec/Minitest, (8) API authentication setup

SKILL.md

4.7 KB, as published. Nobody here has run it

Rails Authentication with Devise

Devise is the most popular authentication solution for Rails, providing a complete MVC solution with 10 modular components.

Quick Setup

# Add to Gemfile
bundle add devise

# Install Devise
rails generate devise:install

# Generate User model with authentication
rails generate devise User

# Run migrations
rails db:migrate

Essential Configuration

After devise:install, configure in config/environments/development.rb:

config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }

Set root route in config/routes.rb:

root to: 'home#index'

Devise Modules Reference

Enable modules in the model (e.g., app/models/user.rb):

ModulePurposeMigration Columns
:database_authenticatablePassword hashing/storageemail, encrypted_password
:registerableSign up, edit, destroy account-
:recoverablePassword reset via emailreset_password_token, reset_password_sent_at
:rememberable"Remember me" cookieremember_created_at
:trackableSign in statssign_in_count, current_sign_in_at, last_sign_in_at, current_sign_in_ip, last_sign_in_ip
:validatableEmail/password validations-
:confirmableEmail confirmationconfirmation_token, confirmed_at, confirmation_sent_at, unconfirmed_email
:lockableLock after failed attemptsfailed_attempts, unlock_token, locked_at
:timeoutableSession expiration-
:omniauthableOAuth provider support-

Controller Helpers

# Require authentication
before_action :authenticate_user!

# Check if signed in
user_signed_in?

# Get current user
current_user

# Access session
user_session

For other models (e.g., Admin):

before_action :authenticate_admin!
admin_signed_in?
current_admin
admin_session

Common Tasks

Add Custom Fields (e.g., username)

  1. Generate migration:
rails g migration AddUsernameToUsers username:string:uniq
rails db:migrate
  1. Permit in ApplicationController:
class ApplicationController < ActionController::Base
  before_action :configure_permitted_parameters, if: :devise_controller?

  protected

  def configure_permitted_parameters
    devise_parameter_sanitizer.permit(:sign_up, keys: [:username])
    devise_parameter_sanitizer.permit(:account_update, keys: [:username])
  end
end

Customize Views

# Generate all views
rails generate devise:views

# Scoped views for specific model
rails generate devise:views users

# Specific modules only
rails generate devise:views -v registrations confirmations

Customize Controllers

# Generate controllers
rails generate devise:controllers users

# Or specific controller
rails generate devise:controllers users -c sessions registrations

Update routes:

devise_for :users, controllers: {
  sessions: 'users/sessions',
  registrations: 'users/registrations'
}

Custom Redirect After Sign In

In ApplicationController:

def after_sign_in_path_for(resource)
  stored_location_for(resource) || dashboard_path
end

def after_sign_out_path_for(resource_or_scope)
  root_path
end

Hotwire/Turbo Configuration (Rails 7+)

In config/initializers/devise.rb:

Devise.setup do |config|
  config.responder.error_status = :unprocessable_entity
  config.responder.redirect_status = :see_other
end

Ensure responders gem version >= 3.1.0.

Testing

RSpec Setup

In spec/support/devise.rb:

RSpec.configure do |config|
  config.include Devise::Test::ControllerHelpers, type: :controller
  config.include Devise::Test::ControllerHelpers, type: :view
  config.include Devise::Test::IntegrationHelpers, type: :feature
  config.include Devise::Test::IntegrationHelpers, type: :request
end

Usage:

sign_in user
sign_out user

Minitest Setup

class ActionDispatch::IntegrationTest
  include Devise::Test::IntegrationHelpers
end

Additional Guides

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.