Skip to content

Configuring devise for APIs

Marc Busqué edited this page Dec 11, 2017 · 4 revisions

Controllers

In order for devise to know it can respond to json format, you need to instruct the controller layer. Usually you will add the following in ApplicationController:

respond_to :json

If you are inheriting from ActionController::API, first you will need to take that functionality back:

include ActionController::MimeResponds

Routes

If you want devise routes to use json as default format (that is, you don't need to add .json at the end of the URLs), use defaults as the following:

devise_for :users, defaults: { format: :json }

Sessions

If you are developing an API, probably you don't need session storage. If you are in a regular Rails application (not created with the --api flag), you can disable them in config/initializers/session_store.rb:

Rails.application.config.session_store :disabled

Clone this wiki locally