devise-token-auth
  • Installation
  • Configuration
    • Initializer Settings
    • OmniAuth
    • Email Authentication
    • Customizing Devise Verbiage
    • Cross Origin Requests (CORS)
  • Usage
    • Mounting Routes
    • Controller Integration
    • Model Integration
    • Using Multiple User Classes
    • Excluding Modules
    • Custom Controller/Email Overrides
    • Reset password flow
    • Testing
  • FAQ
  • Conceptual Diagrams
    • Token Management
    • Batch Requests
  • Security
Powered by GitBook
On this page
  • Example: disable email confirmation
  • Example: disable OAuth authentication
  1. Usage

Excluding Modules

PreviousUsing Multiple User ClassesNextCustom Controller/Email Overrides

Last updated 7 years ago

By default, almost all of the Devise modules are included:

You may not want all of these features enabled in your app. That's OK! You can mix and match to suit your own unique style.

The following example shows how to disable email confirmation.

Example: disable email confirmation

Just list the devise modules that you want to include before including the DeviseTokenAuth::Concerns::User model concern.

# app/models/user.rb
class User < ActiveRecord::Base

  # notice this comes BEFORE the include statement below
  # also notice that :confirmable is not included in this block
  devise :database_authenticatable, :recoverable,
         :trackable, :validatable, :registerable,
         :omniauthable

  # note that this include statement comes AFTER the devise block above
  include DeviseTokenAuth::Concerns::User
end

Some features include routes that you may not want mounted to your app. The following example shows how to disable OAuth and its routes.

Example: disable OAuth authentication

First instruct the model not to include the omniauthable module.

# app/models/user.rb
class User < ActiveRecord::Base

  # notice that :omniauthable is not included in this block
  devise :database_authenticatable, :confirmable,
         :recoverable, :trackable, :validatable,
         :registerable

  include DeviseTokenAuth::Concerns::User
end

Now tell the route helper to skip mounting the omniauth_callbacks controller:

Rails.application.routes.draw do
  # config/routes.rb
  mount_devise_token_auth_for 'User', at: 'auth', skip: [:omniauth_callbacks]
end
database_authenticatable
registerable
recoverable
trackable
validatable
confirmable
omniauthable