From 2f3a59640b39c28934ae5dfce64d600f3f07bf17 Mon Sep 17 00:00:00 2001 From: emersonthis Date: Thu, 14 Mar 2019 14:19:45 -0700 Subject: [PATCH] Added mention of API mode complications to README (#5041) [ci skip] --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 0ecd3e5c..cae2fa3e 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ It's composed of 10 modules: - [ActiveJob Integration](#activejob-integration) - [Password reset tokens and Rails logs](#password-reset-tokens-and-rails-logs) - [Other ORMs](#other-orms) + - [Rails API mode](#rails-api-mode) - [Additional information](#additional-information) - [Heroku](#heroku) - [Warden](#warden) @@ -694,6 +695,17 @@ config.log_level = :warn Devise supports ActiveRecord (default) and Mongoid. To select another ORM, simply require it in the initializer file. +### Rails API Mode + +Rails 5+ has a built-in [API Mode](https://edgeguides.rubyonrails.org/api_app.html) which optimizes Rails for use as an API (only). One of the side effects is that it changes the order of the middleware stack, and this can cause problems for `Devise::Test::IntegrationHelpers`. This problem usually surfaces as an ```undefined method `[]=' for nil:NilClass``` error when using integration test helpers, such as `#sign_in`. The solution is simply to reorder the middlewares by adding the following to test.rb: + +```ruby +Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Cookies +Rails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Session::CookieStore +``` + +For a deeper understanding of this, review [this issue](https://github.com/plataformatec/devise/issues/4696). + ## Additional information ### Heroku