activeadmin: Getting active_admin 401 unauthorized from the latest master
I am currently working on a project where I just have an API ( Rails 4) which uses devise gem for authentication and registration of users. The API is going to be consumed by mobile applications and my client wants to have a backend interface so that he can manage the users information. I have implemented ActiveAdmin but for some reason it is throwing 401 unauthorized error and redirects the login screen:
Started POST "/admin/login" for 127.0.0.1 at 2014-02-19 19:48:04 +0500
Processing by ActiveAdmin::Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"m12gEWvSSAuZdVokA2bdohPErIU74p7MwtKVM2J3+YA=", "admin_user"=>{"email"=>"admin@example.com", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Login"}
AdminUser Load (0.4ms) SELECT `admin_users`.* FROM `admin_users` WHERE `admin_users`.`email` = 'admin@example.com' ORDER BY `admin_users`.`id` ASC LIMIT 1
(0.2ms) BEGIN
SQL (0.4ms) UPDATE `admin_users` SET `last_sign_in_at` = '2014-02-19 14:48:04', `current_sign_in_at` = '2014-02-19 14:48:04', `last_sign_in_ip` = '127.0.0.1', `current_sign_in_ip` = '127.0.0.1', `sign_in_count` = 1, `updated_at` = '2014-02-19 14:48:04' WHERE `admin_users`.`id` = 1
(9.7ms) COMMIT
Redirected to http://localhost:3000/admin
Completed 302 Found in 132ms (ActiveRecord: 10.7ms)
Started GET "/admin" for 127.0.0.1 at 2014-02-19 19:48:04 +0500
Processing by Admin::DashboardController#index as HTML
Completed 401 Unauthorized in 2ms
Started GET "/admin/login" for 127.0.0.1 at 2014-02-19 19:48:04 +0500
Processing by ActiveAdmin::Devise::SessionsController#new as HTML
Rendered /Users/sadanmasroor/.rvm/gems/ruby-2.0.0-p353@love2rent-api/bundler/gems/active_admin-1eca642f8e4d/app/views/active_admin/devise/shared/_links.erb (0.3ms)
Rendered /Users/sadanmasroor/.rvm/gems/ruby-2.0.0-p353@love2rent-api/bundler/gems/active_admin-1eca642f8e4d/app/views/active_admin/devise/sessions/new.html.erb within layouts/active_admin_logged_out (10.0ms)
Completed 200 OK in 21ms (Views: 20.3ms | ActiveRecord: 0.0ms)
I have used ActiveAdmin before many times and never came across such issue. Any thoughts on this ?
About this issue
- Original URL
- State: closed
- Created 10 years ago
- Comments: 20 (7 by maintainers)
On Rails 5 if you want to keep
api_only=true
. you can add this to your application.rbI disabled the session store in
config/initializers/session_store.rb
and this caused the same error. Fixing it just means re-enabling cookies withRails.application.config.session_store :cookie_store
So, it looks like I need
api_only = false
inapplication.rb
and then set upconfig.session_store
since rails-api does not set session management by default, as answered here Solved an issue for me.