Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsJun 1, 2026·3 min de lecture

Devise — Flexible Authentication Solution for Ruby on Rails

A full-featured, modular authentication framework for Rails applications that handles sign-up, sign-in, password recovery, account confirmation, session management, and more.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
Devise Overview
Commande d'installation directe
npx -y tokrepo@latest install b8ec1442-5d71-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

Devise is the most widely adopted authentication library for Ruby on Rails. Built on top of Warden, it provides a complete, modular authentication system that covers everything from user registration and login to password recovery, email confirmation, and session timeout. Developers can enable only the modules they need, keeping the authentication layer lean.

What Devise Does

  • Manages user registration, login, logout, and session lifecycle with sensible defaults
  • Provides password recovery via email with secure token-based reset links
  • Handles email confirmation for new accounts and account locking after failed attempts
  • Supports rememberable tokens for persistent sessions across browser restarts
  • Offers OmniAuth integration for social login with Google, GitHub, Facebook, and other providers

Architecture Overview

Devise is built as a Rails engine composed of ten independent modules, each implemented as a separate concern mixed into the user model. At its core, Devise delegates session management to Warden, a Rack-based authentication middleware. Each module (Database Authenticatable, Registerable, Recoverable, Confirmable, Lockable, Timeoutable, Trackable, Validatable, Rememberable, Omniauthable) can be toggled on or off in the model declaration. Routes, controllers, and views are auto-generated but fully customizable.

Self-Hosting & Configuration

  • Add the gem to your Gemfile and run the install generator to create the initializer at config/initializers/devise.rb
  • Configure mailer settings in your Rails environment for password reset and confirmation emails
  • Customize views with rails generate devise:views to match your application design
  • Override controllers by subclassing Devise controllers when you need custom registration or session logic
  • Set config.secret_key, token expiration times, and password requirements in the initializer

Key Features

  • Ten modular components that can be mixed and matched per model
  • Built-in Warden integration for Rack-level session security
  • OmniAuth support for third-party OAuth providers out of the box
  • Full I18n support with community-maintained locale files for 40+ languages
  • Battle-tested in production across thousands of Rails applications for over a decade

Comparison with Similar Tools

  • Authlogic — lower-level and more manual; Devise provides more out-of-the-box features and generators
  • Clearance — simpler and more opinionated; Devise offers greater flexibility through its module system
  • Sorcery — middleware-free approach; Devise integrates deeper with Rails conventions and provides more built-in modules
  • Rodauth — Sequel-based with a different philosophy; Devise is tightly integrated with ActiveRecord and Rails
  • NextAuth.js / Auth.js — JavaScript ecosystem equivalent; Devise serves the Ruby on Rails ecosystem specifically

FAQ

Q: Can I use Devise with a Rails API-only application? A: Yes. Devise works with API-only apps when paired with a token strategy such as devise-jwt or simple_token_authentication for stateless authentication.

Q: How do I add custom fields to the registration form? A: Override the Devise registrations controller and add your custom parameters to the sign_up_params method using strong parameters.

Q: Does Devise support two-factor authentication? A: Not natively, but the devise-two-factor gem adds TOTP-based 2FA as an additional module that integrates with the existing Devise setup.

Q: Is Devise still maintained? A: Yes. Devise is actively maintained with regular releases, security patches, and Rails version compatibility updates.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires